본문 바로가기

개발/Client Side

[아이폰] 변수 연결하기 - 버튼 누르면 레이블 텍스트 변경

1. 헤더 파일 작성

@interface FirstConnectViewController : UIViewController {

UILabel* label1;

}


@property(nonatomic, retain) IBOutlet UILabel *label1;



2. 구현 파일 작성

@synthesize label1;


3. File's Owner에서 control누른채로 레이블 컨트롤로 끌고 가서 연결


4. 이벤트 작성

헤더

-(IBAction) click:(id)sender;


구현

-(IBAction) click:(id) sender

{

[label1 setText:@"Hello iPhone"];

}


5. 이벤트 연결

(1) 버튼 컨트롤에서 control누른채로 File Owner로 끌고감

(2) Connection Inspector에서 골라서 File Owner로 끌고 감