我在视图中以编程方式创建了2个按钮。两种选择器方法都存在,但它仍然会抛出“无法识别的选择器”错误。我读了一些关于检查僵尸的事情。但是我激活了它(xcode 4.2)并没有看到任何关于任何僵尸的事情。这是代码..
- (void)viewDidLoad
{
for(int i = 0; i < [list count]; i++){
... if statement checks to add text fields
}
UIButton *submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[submit addTarget:self action:@selector(submission:)
forControlEvents:UIControlEventTouchUpInside];
[submit setTitle:@"Submit" forState:UIControlStateNormal];
submit.frame = CGRectMake(x+ 170.0, y, 72, 37);
UIButton *addition = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[addition addTarget:self action:@selector(addition:)
forControlEvents:UIControlEventTouchUpInside];
[addition setTitle:@"Additional Mission" forState:UIControlStateNormal];
addition.frame = CGRectMake(x, y, 140, 37);
y = y+90;
[inputsView addSubview:submit];
[inputsView addSubview:addition];
[inputsView setScrollEnabled:YES];
[inputsView setContentSize:CGSizeMake(320, y)];
}
- (void)submission{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Submission Complete" message:@"Submission"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}
-(void)addition{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Creating Additional Mission" message:@"Additional Mission"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}
有一点需要注意.. inputsView是一个UIScrollView,位于我的viewcontroller中。
提前致谢。
答案 0 :(得分:5)
从选择器方法中删除冒号
[submit addTarget:self action:@selector(submission)
[addition addTarget:self action:@selector(addition)
冒号告诉选择器这个方法接受参数,你的不是这样冒号不应该是选择器的一部分
答案 1 :(得分:1)
[add addTarget:self action:@selector(addition :)
在这一行中你说你的选择器@selector(addition:)
需要一个加法后冒号的参数
但在你的真实方法
-(void)addition{
添加后没有参数..这就是崩溃的原因..在提交和添加中删除冒号,你会很高兴。