0

我在 xcode 中遇到了一个奇怪的问题。我在 xib 中创建了一个按钮并连接到一个函数。我正在函数内打印消息。就是这样,当我单击按钮时,出现以下错误。我尝试从我的模拟器中清理并删除应用程序。

-(IBAction)languageSelection:(id)sender是我的函数名

-[NSCFString languageSelection:]: unrecognized selector sent to instance 0x713cd40
2012-05-03 15:14:35.055 Example[33420:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString languageSelection:]: unrecognized selector sent to instance 0x713cd40'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02966919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02ab45de objc_exception_throw + 47
    2   CoreFoundation                      0x0296842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x028d8116 ___forwarding___ + 966
    4   CoreFoundation                      0x028d7cd2 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x005ece14 -[UIApplication sendAction:to:from:forEvent:] + 119
    6   UIKit                               0x006766c8 -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00678b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    8   UIKit                               0x006776f7 -[UIControl touchesEnded:withEvent:] + 458
    9   UIKit                               0x006102ff -[UIWindow _sendTouchesForEvent:] + 567
    10  UIKit                               0x005f21ec -[UIApplication sendEvent:] + 447
    11  UIKit                               0x005f6ac4 _UIApplicationHandleEvent + 7495
    12  GraphicsServices                    0x02dedafa PurpleEventCallback + 1578
    13  CoreFoundation                      0x02947dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x028a8737 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x028a59c3 __CFRunLoopRun + 979
    16  CoreFoundation                      0x028a5280 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x028a51a1 CFRunLoopRunInMode + 97
    18  GraphicsServices                    0x02dec2c8 GSEventRunModal + 217
    19  GraphicsServices                    0x02dec38d GSEventRun + 115
    20  UIKit                               0x005fab58 UIApplicationMain + 1160
    21  Example                             0x000023c9 main + 121
    22  Example                             0x00002345 start + 53
)
terminate called after throwing an instance of 'NSException'
4

1 回答 1

2

这可能是您尝试使用实际上是字符串的对象调用方法 languageSelection ,但是您已传递给另一个具有 languageSelection 方法的对象。

这是因为您认为该对象是您想要的,但指针将分配的内存传递给字符串,因此它将作为字符串工作。当您尝试调用方法时,它会崩溃,因为它没有在字符串中找到该方法。在您在任何地方使用它之前检查您的对象类型

于 2012-05-03T09:56:43.950 回答