본문 바로가기

프로그래밍/아이폰 프로그래밍

(37)
13. 프로퍼티의 속성 키워드와 설명 readonly - 프로퍼티가 변경되지 않도록 할때 사용한다. 컴파일러가 세터를 자동으로 생성해 주지 않는다. retain - 객체의 값을 다룰 때 주로 사용한다. 메모리 해제를 위해 retain count를 사용하는데 값이 0이 되면 메모리에서 해제한다. readwrite - 프로퍼티를 변경할 필요가 있을 때 사용한다. 컴파일러는 게터와 세터를 생성해 준다. (기본값) copy - 전달된 원래의 값이 변경되지 않도록 할 때 사용한다. assign - int 나 float와 같은 기본형을 다룰 때 사용한다. 객체를 다룰 때에는 메모리 관리 측면에서 적절하지 않다. ※ nonatomic - 뮤텍스( mutex )를 사용하지 않음 : 멀티 쓰레드 환경 아님.
12. 헤더파일에 대한 설명 // 이것은 C언어의 #include와 동일하다. 그러나 자동으로 중복 인클루드 되는 것을 막아준다. #import // @interface - 클래스 정의를 나타내는 키워드 // 하나의 클래스가 구현할 수 있는 프로토콜의 수의 제한은 없다. @interface ClassName : 상속 { // IBOutlet으로 명시하면 인터페이스 빌더가 인식해서 이 변수와 UI 컴포넌트를 연결할 수 있다. IBOutlet UIPickerView *tweetPicker; // 여기에 클래스의 필드를 선언할 수 있다. NSArray* activities; } // @property 키워드는 이것이 컴파일러에 의해서 게터와 세터가 만들어질 프로퍼티라고 알려준다. @property ( nonato..
11. 피커 사용하기 (UIPickerView) 헤더파일. #import // 피커를 사용하기 위해서는 아래와 같은 2개의 프로토콜을 반드시 사용해야 한다. @interface InstaTwitViewController : UIViewController { NSArray* activities; // 피커에 넣어줄 데이터 소스를 담아줄 배열 NSArray* feelings; IBOutlet UIPickerView *tweetPicker; } @end .m파일. // 뷰를 로드한 후 배열을 초기화 한다. 피커에 넣어줄 데이터 소스이다. - (void)viewDidLoad { [super viewDidLoad]; activities = [[NSArray alloc] initWithObjects:@"sleeping",@"eating",@"working",ni..
10. 시작화면 적용하기 앱이 시작될 때까지 걸리는 로딩 시간에 표시 화면을 지정할 수 있다. iPhone 3GS - 크기 : 320 * 480 - 이름 : Default.png iPhone 4 - 크기 : 640 * 960 - 이름 : Default@2x.png 두 파일을 Resources폴더에 넣어둔다.
9. 램덤값 가져오기 arc4random() - 예제 #define RANDOM_INT(MIN, MAX) ((MIN) + arc4random() % ((MAX+1) - (MIN))) - 사용 int rand1 = RANDOM_INT(0,320); int rand2 = RANDOM_INT(0,480);
8. 애니메이션 사용하기 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; // 애니메이션 동작 시간 : 1.0초 [UIView setAnimationDelegate:self]; // 여기서 구현 [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; // 서서히 느려짐 // 예제... 이 안에서 객체의 위치,크기,알파 등의 변화가 있으면 저절로 애니메이션이 적용된다. //......................................................................... CGAffineTransform transform = CGAffineTransformMakeSc..
7. 타이머 사용 (NSTimer) 헤더파일. @interface MainViewController : UIViewController { NSTimer *timer; UILabel *lblTimeDigit; } @property(retain, nonatomic) NSTimer *timer; @property(retain, nonatomic) UILabel *lblTimeDigit; @end .m 파일. @implementation MainViewController @synthesize timer; @synthesize lblTimeDigit; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLo..
6. NSMutableArray 사용 및 이미지 동적 생성하기 1. NSMutableArray를 헤더파일에 등록시킨다. @interface MainViewController { NSMutableArray *arrayImages; } @property(retain, nonatomic) NSMutableArray *arrayImages; @end 2. 헤더파일에 등록된 array를 .m 파일에 사용한다. @implementation MainViewController @synthesize arrayImages; // 등록 // 프로그램 시작점 - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor blackColor]]; // 배경 셋팅하기 arrayImages = [[NSMuta..