【问题标题】:Perform segue from unbutton results in "unrecognized selector" error从 unbutton 执行 segue 导致“无法识别的选择器”错误
【发布时间】:2012-08-30 17:37:51
【问题描述】:

我已经通过单击按钮实现了一个简单的 segue。这是视图控制器代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
   {
{
    if (self.categoryInt == 1)
        [segue.destinationViewController setCategoryKey:SD_ADDITION];
    else if (self.categoryInt == 2)
       [segue.destinationViewController setCategoryKey:SD_SUBTRACTION];

}}

- (IBAction)category1Selected:(id)sender {
self.categoryInt = 1;
[self performSegueWithIdentifier:@"ShowWorksheet" sender:self];}

从日志消息中,我可以看到它完全通过目标视图控制器上的 ViewDidLoad 运行,但随后出错 与:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[MainMenuViewController categorySelected:]:无法识别的选择器发送到实例 0x75360e0”

我没有在这些按钮上实现任何特定的选择器。我的 MainMenuViewController 中也没有“categorySelected”方法。被调用的方法是“category1Selected”。是什么导致了这个错误?

【问题讨论】:

  • 确保您的 IBAction 在 Interface Builder 中正确连接。

标签: objective-c ios xcode


【解决方案1】:

我想你自己回答了这个问题。当您应该发送 category1Selected 时,您以某种方式发送“categorySelected”。

检查您之前是否在界面生成器中将按钮连接到 categorySelected。如果您之前已这样做,但随后在代码中将 categorySelected 的名称更改为 category1Selected,则界面生成器可能不会更新。

【讨论】:

  • 谢谢。这就是问题所在。删除了之前的连接。
【解决方案2】:

这通常是连接错误,请转到您的连接检查器并确保那里一切正确。

如果您不确定断开所有连接并重新建立连接,请仔细检查所有内容。

此外,请确保您没有将操作按钮连接为除了其操作命令之外的插座。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-29
    • 1970-01-01
    相关资源
    最近更新 更多