【问题标题】:Unrecognised selector error on button press按下按钮时出现无法识别的选择器错误
【发布时间】:2012-06-08 10:58:40
【问题描述】:

基本上,我得到了错误:

-[UIViewController donePress:]: unrecognized selector sent to instance 0x6a7f7c0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController donePress:]: unrecognized selector sent to instance 0x6a7f7c0'
*** First throw call stack:
(0x13cd022 0x155ecd6 0x13cecbd 0x1333ed0 0x1333cb2 0x13cee99 0x1a14e 0x1a0e6 0xc0ade 0xc0fa7 0xc0266 0x3f3c0 0x3f5e6 0x25dc4 0x19634 0x12b7ef5 0x13a1195 0x1305ff2 0x13048da 0x1303d84 0x1303c9b 0x12b67d8 0x12b688a 0x17626 0x1d6d 0x1cd5)
terminate called throwing an exception

每当我按下一个按钮。此按钮位于第二个视图中,由以下人员加载:

replacementController = [[UIViewController alloc] initWithNibName:@"NFCController" bundle:nil];
[self.view addSubview:self.replacementController.view];

通过使用拆分窗格视图和控件拖动到头文件,该按钮已连接到一个类。 Xcode 生成了相关的方法。但是,现在当我单击按钮时,它会因上述错误而崩溃。

如果您需要更多信息,请告诉我。

谢谢

【问题讨论】:

    标签: objective-c ios cocoa-touch uiviewcontroller uibutton


    【解决方案1】:

    您正在初始化 UIViewController 而不是 NFCController

    把初始化改成

    replacementController = [[NFCController alloc] initWithNibName:@"NFCController" bundle:nil];
    

    说明:正在创建的对象是 UIViewController 而不是 NFCController 并且 UIViewController 没有一个名为 donePress: 的函数,因此您会收到错误

    【讨论】:

    • 完美。我看不到它。
    • 多次犯同样的错误,感谢奥马尔先生的提醒。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 2014-08-26
    • 2017-08-30
    • 1970-01-01
    • 2012-04-04
    相关资源
    最近更新 更多