반응형
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iPhone Objective C example | |
// Window based 어플리케이션 선택 : wizard 에 의하여 생성 | |
#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 |
728x90
반응형
'iOS' 카테고리의 다른 글
iPhone 3 프로세스(process) 메모리(memory) 크기(size) (0) | 2010.05.21 |
---|