选择器调用成功后,无法识别的选择器立即发送错误
这个错误让我感到困惑,但这里是:
我试图设置一个 IBAction 以在 UIButton 内部的触摸上运行。由于某种原因,它不起作用,并且没有真正给我任何 gdb 错误。它时不时地会提到一个无法识别的选择器。我检查以确保我的文件的所有者是正确的类,并且一切都在检查中,所以我再次运行它,但仍然没有任何结果。
我认为这可能是 Interface Builder 的问题,所以我在按钮上使用了 addTarget: ,将目标设置为 self,选择器设置为我要调用的方法的选择器,但仍然出现无法识别的选择器错误。为了测试选择器是否存在,我在我想要的方法的选择器上运行了 [self PerformSelector:],并且它起作用了。所以基本上现在我有这个:
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(hi)];
[_backButton addTarget:self action:@selector(hi) forControlEvents:UIControlEventTouchUpInside];
}
- (void)hi {
NSLog(@"HI");
}
执行选择器工作完美,并记录“HI”。这是关键之处,当我触摸 _backButton 时,它给了我一个无法识别的选择器错误,即使我刚刚调用它并且它起作用了:
2011-10-22 19:54:40.824 VideoGif[396:707] -[NSKeyValueObservance hi]: unrecognized selector sent to instance 0x590690
2011-10-22 19:54:40.831 VideoGif[396:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSKeyValueObservance hi]: unrecognized selector sent to instance 0x590690'
我已经拍摄了笔尖和实现文件的屏幕截图,可以在此处查看: https://i.sstatic.net/D9GsW.jpg
有人知道发生了什么事吗?
This bug is befuddling to me, but here goes:
I was trying to set up an IBAction to run on touch up inside on a UIButton. For some reason, it wasn't working, and wasn't really giving me any gdb errors. Every now and then it would mention an unrecognized selector. I checked to make sure my File's owner was the correct class, and everything was in check and it was, so I ran it again and still nothing.
I figured it might be a problem with Interface Builder, so I used addTarget: on the button, setting the target as self, and the selector the selector of the method I wanted to call, and still got an unrecognized selector error. To test that the selector did exist, I ran a [self performSelector:] on the selector of the method I wanted, and it worked. So basically right now I have this:
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(hi)];
[_backButton addTarget:self action:@selector(hi) forControlEvents:UIControlEventTouchUpInside];
}
- (void)hi {
NSLog(@"HI");
}
The perform selector works perfectly, and logs "HI". Here's the kicker, when I touchup on _backButton, it gives me an unrecognized selector error, even though I just called it and it worked:
2011-10-22 19:54:40.824 VideoGif[396:707] -[NSKeyValueObservance hi]: unrecognized selector sent to instance 0x590690
2011-10-22 19:54:40.831 VideoGif[396:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSKeyValueObservance hi]: unrecognized selector sent to instance 0x590690'
I've taken screen shots of the nib and the implementation file, viewable here: https://i.sstatic.net/D9GsW.jpg
Does anyone know what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题的发生可能是因为您的 CaptionEditorViewController 实例由于某种原因被释放,正如随机类抛出“无法识别的选择器”异常所指出的那样
The problem is probably happening because your instance of CaptionEditorViewController is being deallocated for some reason, as pointed by random classes throwing "unrecognized selector" exceptions