objective-c – [__ NSCFType searchKeyword:]:无法识别的选择器发送到实例0x6d8eb80

以下代码是从storyboard向当前视图添加子视图:
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:]: unrecognized selector sent to instance 0x6d8eb80

2012-05-26 20:26:47.369 OnlineBooking[6607:f803] * WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDomrange:givenAction: delegate: -[__NSCFType searchKeyword:]: unrecognized selector sent to instance 0x6d8eb80

解决方法

您需要保留EventSearchViewController,或者如果您使用ARC,请保留对它的强引用.如果将它作为局部变量分配给view1,那么在调用searchKeyword:时它就不会再存在了. (错误显示其内存已释放并重新用于其他类型的对象.)

相关文章

对象的传值与返回说起函数,就不免要谈谈函数的参数和返回值...
从实现装饰者模式中思考C++指针和引用的选择最近在看...
关于vtordisp知多少?我相信不少人看到这篇文章,多半是来自...
那些陌生的C++关键字学过程序语言的人相信对关键字并...
命令行下的树形打印最近在处理代码分析问题时,需要将代码的...
虚函数与虚继承寻踪封装、继承、多态是面向对象语言的三大特...