【发布时间】:2014-03-08 15:29:53
【问题描述】:
我有一个带有五个按钮的视图控制器。每个按钮都应该根据按钮的标签触发一个模态segue到不同的视图控制器,由声明的常量表示:
- (IBAction)aButtonTapped:(UIButton *)sender
{
[self buttonForSegue:sender];
}
-(void) buttonForSegue:(UIButton *)sender
{
switch ([sender tag])
{
case aVsAButton_tag:
[self performSegueWithIdentifier:@"aVsAModal" sender:self];
break;
case cVsCButton_tag:
[self performSegueWithIdentifier:@"cVsCModal" sender:self];
break;
case actVsAllButton_tag:
[self performSegueWithIdentifier:@"actVsAllModal" sender:self];
break;
case catVsAllButton_tag:
[self performSegueWithIdentifier:@"catVsAllModal" sender:self];
break;
case customDatePickerButton_tag:
[self performSegueWithIdentifier:@"customDatePickerModal" sender:self];
break;
default:
break;
}
}
无论我点击哪个按钮,应用程序都会在 sim 卡中崩溃并显示此消息(仅按钮名称更改):
2014-02-10 19:11:47.305 WMDGx[24366:a0b] -[ReportViewController aVsAllButton:]:无法识别的选择器发送到实例 0x8a911e0 2014-02-10 19:11:47.307 WMDGx[24366:a0b] * ** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[ReportViewController aVsAllButton:]:无法识别的选择器发送到实例 0x8a911e0”
我的代码在我看来是合理的,但显然不是。谁能告诉我哪里出错了?
谢谢!
【问题讨论】:
-
这个问题与你的 switch 语句无关。崩溃告诉你具体的问题。您正在调用
ReportViewController上的选择器,但它没有响应。您需要显示调用aVsAllButton:选择器的代码。 -
@Jeremy--Duncan C 在第二个答案中指出了这一点。感谢您的回复!
标签: ios objective-c switch-statement