希望有人可以帮我解释为什么我应该添加:调用方法。
这是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];
}
这是Button Pressed方法
-(void)buttonPressed:(UIButton *)sender{
NSLog(@"This button was pressed");
self.view.alpha=((double)arc4random()/0x100000000);
}
当我删除:from
[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 2012-12-29 17:56:18.210 AlphaSchoolColor [11414:c07] * 由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [com_skminfotekViewController buttonPressed]:无法识别的选择器发送到实例0xde2f050'
对社区的问题是发生了什么:我可以从哪些更多的信息中了解它的重要性。
感谢。
答案 0 :(得分:3)
你的方法有一个arg。如果您想在没有“:”的情况下发送动作,请更改您的方法。
-(void)buttonPressed{
}