メソッドを呼び出すために : を追加する必要がある理由について、誰かが私を助けてくれることを願っています。
これがviewDidLoadメソッドです
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor= [UIColor yellowColor];
//Add Button
CGRect buttonRect= CGRectMake(100, 100, 100, 44);
UIButton *clickButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[clickButton setFrame: buttonRect];
[clickButton setTitle:@"Click Me" forState: UIControlStateNormal];
[clickButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:clickButton];
[self buttonPressed:clickButton];
//Add UILabel
CGRect labelViewRect= CGRectMake(50, 30, 200, 44);
UILabel *labelview= [[UILabel alloc]initWithFrame:labelViewRect];
[labelview setText:@"Hello welcome to my app!"];
//Clear the UIView button's background
[labelview setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:labelview];
}
ボタンを押す方法は次のとおりです
-(void)buttonPressed:(UIButton *)sender{
NSLog(@"This button was pressed");
self.view.alpha=((double)arc4random()/0x100000000);
}
から : を削除すると
[clickButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
つまり、上記の行を次のように変更しています
[clickButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
例外がスローされます。
2012-12-29 17:56:18.209 AlphaSchoolColor[11414:c07] -[com_skminfotekViewController buttonPressed]: 認識されないセレクターがインスタンス 0xde2f050 に送信されました例外 'NSInvalidArgumentException'、理由: '-[com_skminfotekViewController buttonPressed]: 認識されないセレクターがインスタンス 0xde2f050 に送信されました'
コミュニティへの質問は、それで何が起こっているのかです:そして、その重要性について私が知ることができる情報はどこにありますか.
ありがとう。