ViewController.h
UILabelの追加
クラスにUILabelのオブジェクトを追加します
@interface StudyViewController : UIViewController { // UILabelの追加 IBOutlet UILabel * label; }
ボタンアクションの追加
- (IBAction) push:(id)sender;
プロパティの追加
@property (nonatomic, retain) IBOutlet UILabel *label;
ViewController.m
プロパティの初期化
UILabelを初期化します。
@synthesize label;
テキストの設定
アプリ起動時に表示させるテキストをviewDidLoadのメソッドに追加します
- (void)viewDidLoad { label.text = @"Hello World!"; [super viewDidLoad]; }
pushメソッドを追加し、テキストを変更させます。
- (void)push : (id)sender { label.text = "Push Button";
}
UILabelの解放
dellocメソッドにラベルの解放を追加します。
- (void)dealloc { [label dealloc]; [super dealloc]; }
XIBの編集
画面にLabelを配置します。
File's Ownerと接続します。
画面のLabelからControlキーを押しながらFile's Ownerと接続してください
画面にボタンを配置します
File's Ownerと接続します。
画面のボタンからControlキーを押しながらFile's Ownerと接続してください