2010年7月23日金曜日

HelloWorldのコード

HelloKouchiViewController.h

#import

@interface HelloKouchiViewController : UIViewController {
// IB(Interface Builder)上のコントロールと結びつけるためのアウトレットを宣言
IBOutlet UILabel *label;
IBOutlet UIButton *helloButton;
// バラーメータの宣言
NSInteger i;

}
// プロパティ名を宣言
@property(nonatomic, retain) UILabel *label;
@property(nonatomic, retain) UIButton *helloButton;

/*
IBActionと記述することによってInterface Builderでこのメソッドactionとしてを認識できるようになります
helloButtonボタンを押した時のアクション
*/
- (IBAction) helloAction;

@end



HelloKouchiViewController.m

#import "HelloKouchiViewController.h"

@implementation HelloKouchiViewController

@synthesize label;// UILabel
@synthesize helloButton;// UIButton



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
i = 0;// 初期化
}

#pragma mark - IBAction
- (IBAction) helloAction{
if ( i % 2 == 0) {// !!!:もし i を 2で割ったときにあまりが0なら
self.label.text = @"Hello World!!";
NSLog(@"self.label.text:%@",self.label.text);
i++;// i = i + 1;
}else {
self.label.text = @"";
i++;
}
}



- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
[label release];
[helloButton release];
}

@end

0 件のコメント:

コメントを投稿