Objective c “接收”-[uu NSCFNumber按钮按下:]:发送到实例的无法识别的选择器";点击UIButton时出错

Objective c “接收”-[uu NSCFNumber按钮按下:]:发送到实例的无法识别的选择器";点击UIButton时出错,objective-c,xcode,Objective C,Xcode,我有一个具有多个计划NIB的视图控制器选项ViewController类。我正在尝试创建第一个NIB,三个选项ViewController.xib。界面文件有多个按钮,单击这些按钮时,应调用OptionsViewController中显示的方法按钮。我的按键功能很简单: - (IBAction)buttonPressed:(id)sender { NSLog(@"buttonPressed"); } 但是,当我点击按钮时,我收到以下错误: 2015-03-18 01:12:52.972

我有一个具有多个计划NIB的视图控制器选项ViewController类。我正在尝试创建第一个NIB,三个选项ViewController.xib。界面文件有多个按钮,单击这些按钮时,应调用OptionsViewController中显示的方法按钮。我的按键功能很简单:

- (IBAction)buttonPressed:(id)sender {
    NSLog(@"buttonPressed");
}
但是,当我点击按钮时,我收到以下错误:

2015-03-18 01:12:52.972 Yoyo[1961:29189] -[__NSCFNumber buttonPressed:]: unrecognized selector sent to instance 0x7fe1052670f0
2015-03-18 01:12:52.980 Yoyo[1961:29189] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber buttonPressed:]: unrecognized selector sent to instance 0x7fe1052670f0'
我知道这个错误通常发生在程序在错误的类中查找方法时,或者出现拼写错误时。但是ThreeOptionsViewController.xib的文件所有者类名设置为OptionsViewController。我通过从一个按钮拖动到另一个按钮来连接这些按钮。我知道NIB确实连接到OptionViewController,因为我有按钮的IBOutlet,并且按钮根据OptionViewController的代码进行了适当修改

我还尝试通过删除XIB文件中的连接并将以下行添加到OptionViewController的viewDidLoad方法中,以编程方式添加该操作:

[_button1 addTarget:self action:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];
但我也犯了同样的错误。我不明白为什么程序不寻找ObjectsViewController中的按钮,以及这个数字究竟与此有什么关系。完整输出为:

2015-03-18 01:12:52.972 Yoyo[1961:29189] -[__NSCFNumber buttonPressed:]: unrecognized selector sent to instance 0x7fe1052670f0
2015-03-18 01:12:52.980 Yoyo[1961:29189] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber buttonPressed:]: unrecognized selector sent to instance 0x7fe1052670f0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010f7cba75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010f464bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010f7d2d1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x000000010f72a9dc ___forwarding___ + 988
    4   CoreFoundation                      0x000000010f72a578 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x000000010fbbca22 -[UIApplication sendAction:to:from:forEvent:] + 75
    6   UIKit                               0x000000010fcc3e50 -[UIControl _sendActionsForEvents:withEvent:] + 467
    7   UIKit                               0x000000010fcc321f -[UIControl touchesEnded:withEvent:] + 522
    8   UIKit                               0x000000010ff6ae80 _UIGestureRecognizerUpdate + 9487
    9   UIKit                               0x000000010fc02856 -[UIWindow _sendGesturesForEvent:] + 1041
    10  UIKit                               0x000000010fc03483 -[UIWindow sendEvent:] + 667
    11  UIKit                               0x000000010fbcffb1 -[UIApplication sendEvent:] + 246
    12  UIKit                               0x000000010fbdd227 _UIApplicationHandleEventFromQueueEvent + 17700
    13  UIKit                               0x000000010fbb823c _UIApplicationHandleEventQueue + 2066
    14  CoreFoundation                      0x000000010f700c91 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x000000010f6f6b5d __CFRunLoopDoSources0 + 269
    16  CoreFoundation                      0x000000010f6f6194 __CFRunLoopRun + 868
    17  CoreFoundation                      0x000000010f6f5bc6 CFRunLoopRunSpecific + 470
    18  GraphicsServices                    0x000000011135da58 GSEventRunModal + 161
    19  UIKit                               0x000000010fbbb580 UIApplicationMain + 1282
    20  Yoyo                                0x000000010da84a63 main + 115
    21  libdyld.dylib                       0x0000000111965145 start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

如何创建button1,以及如何为其赋值?它是从NIB创建的,并通过标准IBOutlet访问。不过我还是解决了我的问题。正如其他人可能猜到的那样,这是一个内存管理不善的案例。包含buttonPressed的ViewController由父ViewController初始化,但据我所知,它没有被保留。我通过将初始化的ViewController分配给父ViewController的.h文件中创建的strong@属性来修复它。