简体   繁体   English

无法识别的选择器已发送到实例

[英]unrecognized selector sent to instance

I have added a tabbarcontroller on window and a button on view respective to first tab. 我在窗口上添加了一个tabbarcontroller,在视图上添加了一个按钮,分别对应于第一个标签。 As I run the app and press the button, the app is crashing with this msg: 当我运行该应用程序并按下按钮时,该应用程序因以下消息而崩溃:

2011-05-20 18:56:46.258 FeatureList[3395:207] -[UIViewController barButtonPressed:]: unrecognized selector sent to instance 0x4b22520
2011-05-20 18:56:46.262 FeatureList[3395:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController barButtonPressed:]: unrecognized selector sent to instance 0x4b22520'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00da9be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00efe5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x00dab6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00d1b366 ___forwarding___ + 966
    4   CoreFoundation                      0x00d1af22 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002b2a6e -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x003411b5 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00343647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x003421f4 -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x002d70d1 -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x002b837a -[UIApplication sendEvent:] + 447
    11  UIKit                               0x002bd732 _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x016dfa36 PurpleEventCallback + 1550
    13  CoreFoundation                      0x00d8b064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x00ceb6f7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x00ce8983 __CFRunLoopRun + 979
    16  CoreFoundation                      0x00ce8240 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x00ce8161 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x016de268 GSEventRunModal + 217
    19  GraphicsServices                    0x016de32d GSEventRun + 115
    20  UIKit                               0x002c142e UIApplicationMain + 1160
    21  FeatureList                         0x000024fc main + 102
    22  FeatureList                         0x0000248d start + 53
    23  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
kill
quit

The Debugger has exited with status 0.(gdb) 调试器已退出,状态为0。(gdb)

This happens when you try to call a method that doesn't exist. 当您尝试调用不存在的方法时,会发生这种情况。 It looks like you've set up your button to send a message to the view controller (barButtonPressed:), but you may not have implemented the method if your view controller. 看起来您已经设置了向视图控制器发送消息的按钮(barButtonPressed :),但是如果您使用视图控制器,则可能尚未实现该方法。 Or you may have misspelled the method name or not included the argument in the method implementation. 或者您可能拼错了方法名称,或者未在方法实现中包含参数。

Post your view controller code. 发布您的视图控制器代码。

This is an old question, but I think I know what happened. 这是一个老问题,但我想我知道发生了什么。 Notice how the error message says UIViewController instead of TodayDeal; 注意错误消息显示的是UIViewController而不是TodayDeal; he needed to change the Xib's file owner from a default UIViewController to TodayDeal 他需要将Xib的文件所有者从默认的UIViewController更改为TodayDeal

It looks like the button is trying to call barButtonPressed: on the view controller, but that method doesn't exist. 看起来该按钮正在尝试在视图控制器上调用barButtonPressed:,但是该方法不存在。 Are you sure you don't get warnings during compilation regarding missing methods? 您确定在编译过程中没有收到关于缺少方法的警告吗? My guess is you're not setting the view controller class correctly in a nib file. 我的猜测是您没有在nib文件中正确设置视图控制器类。

Have you implemented barButtonPressed: ? 您实现了barButtonPressed:吗? Are you sure you need the colon? 您确定需要冒号吗? Try barButtonPressed as the selector name instead. 尝试使用barButtonPressed作为选择器名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM