点击背景时为什么我的应用程序崩溃?

时间:2015-04-04 05:36:52

标签: ios objective-c selector

当应用程序进入警报状态并按下背景图像时,我收到以下错误消息。

2015-04-04 01:06:39.583 APP[479:44057] -[__NSCFString resignFirstResponder]: unrecognized selector sent to instance 0x16d627c0
2015-04-04 01:06:39.584 APP[479:44057] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString resignFirstResponder]: unrecognized selector sent to instance 0x16d627c0'
*** First throw call stack:
(0x270e35a7 0x34cc9c77 0x270e8a6d 0x270e6949 0x27017b68 0x4ed91 0x2a76507f 0x2a6139ed 0x2aa29951 0x2a5dd3c5 0x2a5db33f 0x2a611ddd 0x2a6116ad 0x2a5e7fbd 0x2a85bbb5 0x2a5e6a07 0x270aa237 0x270a964b 0x270a7cc9 0x26ff4b51 0x26ff4963 0x2e5331a9 0x2a646c91 0x4ca35 0x35272aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException

通常这个屏幕没有错误,它只是在我为应用程序设置警报状态后才会发生。该应用程序使用此方法关闭故事板中某些视图的键盘。

-(void)dismissKeyboard { 
[message resignFirstResponder]; 
[contact1 resignFirstResponder]; 
[contact2 resignFirstResponder]; 
[contact3 resignFirstResponder]; 
}

1 个答案:

答案 0 :(得分:1)

通过与杰克的聊天,看起来崩溃的罪魁祸首是由于一种方法:

-(void)dismissKeyboard
{
    // ------------------------------------------------------
    // These variables appear to be NSString, so it crashes
    // ------------------------------------------------------
    [message resignFirstResponder];
    [contact1 resignFirstResponder];
    [contact2 resignFirstResponder];
    [contact3 resignFirstResponder];
}

所以解决方案就是将其改为:

-(void)dismissKeyboard
{
    [self.view endEditing:YES];
}