[__NSCFType searchKeyword:]:无法识别的选择器发送到实例0x6d8eb80

时间:2012-05-26 12:45:46

标签: objective-c unrecognized-selector uncaught-exception

以下代码是从故事板向当前视图添加子视图:

EventSearchViewController* view1 = [self.storyboard instantiateViewControllerWithIdentifier:@"searchView"];

[view1 setBookingSystem:system];

[self.view addSubview:view1.view];

在视图“view1”中,有一个textField。以下是textField的IBAction,事件是“退出时结束”。

-(IBAction)searchKeyword:(id *)sender
{
    NSLog(@"searchKeyword");
}

以下是错误消息。

  

2012-05-26 20:26:47.369 OnlineBooking [6607:f803] - [__ NSCFType searchKeyword:]:无法识别的选择器发送到实例0x6d8eb80

     

2012-05-26 20:26:47.369 OnlineBooking [6607:f803] * WebKit在webView中丢弃了未捕获的异常:shouldInsertText:replacementDOMRange:givenAction:delegate: - [__ NSCFType searchKeyword:] :无法识别的选择器发送到实例0x6d8eb80

2 个答案:

答案 0 :(得分:12)

如果您使用的是ARC,则需要保留EventSearchViewController,或者对其进行强有力的引用。如果将其作为局部变量分配给view1,则在searchKeyword:被调用时不会再出现这种情况。 (错误显示其内存已被释放并重新用于其他类型的对象。)

答案 1 :(得分:0)

对我来说问题是我从未打电话给

- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
在我打电话之前

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

试。