'iphone example'에 해당되는 글 1건

  1. 2010.05.15 iPhone example 01
Computer Language2010. 5. 15. 21:27

(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


반응형
Posted by Jay Two