반응형
(1) window based 어플리케이션 선택 : wizard 에 의하여 생성.
(2) 헤더 파일 (*.h)
#import <UIKit/UIKit.h>
@interface ex20ViewController : UIViewController {
UILabel *labelText; // IB(Interface Builder)에 연결할 컨트롤 추가: Label 컨트롤
}
@property (nonatomic, retain) IBOutlet UILabel *labelText; // 추가: UILabel 컨트롤
// @property (nonatomic, retain) IBOutlet 는
// IB(InterfaceBuilder)를 사용하는 컨트롤에서 거의 의무적으로 넣어주자...
-(IBAction) buttonAction:(id)sender;
// 컨트롤에 연결할 함수 추가: 항상 (IBAction) 정의 필요
@end
(3) *.m 파일
@implementation ex20ViewController
@synthesize labelText; // 추가; [컨트롤]과 [XIB] 연결
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil
self.labelText = nil; // 추가: unload 처리
}
- (void)dealloc {
[labelText release]; // 추가: dealloc 처리
[super dealloc];
}
// 추가: IB에서 연결하여 사용
-(IBAction) buttonAction : (id)sender { // sender는 UIButton* 이다. 버튼과 연결함.
NSString* title = [sender titleForState:UIControlStateNormal]; // returns the title used for a state.
NSString* newText = [[NSString alloc] initWithFormat:@"%@ button pressed.", title];
labelText.text = newText; // set label text
[newText release];
}
@end
반응형
'Computer Language' 카테고리의 다른 글
TIOBE Programming Community Index for February 2012 (0) | 2012.03.08 |
---|---|
가장 많이 사용하는 프로그래밍 언어, 2011년 5월 (TIOBE Programming Community Index for May 2011) (0) | 2011.05.18 |
iPhone 3 프로세스(process) 메모리(memory) 크기(size) (0) | 2010.05.21 |
표준화 작업 (0) | 2009.03.08 |
디버깅 훈련 (0) | 2008.11.06 |