【发布时间】:2013-12-21 01:01:22
【问题描述】:
我有一个无法识别的选择器发送到实例问题。我知道哪条线路有问题,但我不明白为什么它不能识别它。 (我在创建容器视图时测试了这段代码,它工作得很好。但由于某种原因,当我将它合并到我的主项目时,我收到了这个错误。)
这是我的控制台输出:
2013-12-20 16:47:59.633[8545:70b] -[UIViewController decideViewController:]: unrecognized selector sent to instance 0x8b5c250
2013-12-20 16:47:59.659[8545:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController decideViewController:]: unrecognized selector sent to instance 0x8b5c250'
*** First throw call stack:
(
0 CoreFoundation 0x01c075e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0198a8b6 objc_exception_throw + 44
2 CoreFoundation 0x01ca4903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01bf790b ___forwarding___ + 1019
4 CoreFoundation 0x01bf74ee _CF_forwarding_prep_0 + 14
5 TProduct 0x0000566f -[GameViewController changeViews:] + 143
6 TProduct 0x00005404 -[GameViewController timerTick:] + 532
7 Foundation 0x015c1927 __NSFireTimer + 97
8 CoreFoundation 0x01bc5bd6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
9 CoreFoundation 0x01bc55bd __CFRunLoopDoTimer + 1181
10 CoreFoundation 0x01bad628 __CFRunLoopRun + 1816
11 CoreFoundation 0x01bacac3 CFRunLoopRunSpecific + 467
12 CoreFoundation 0x01bac8db CFRunLoopRunInMode + 123
13 GraphicsServices 0x0387b9e2 GSEventRunModal + 192
14 GraphicsServices 0x0387b809 GSEventRun + 104
15 UIKit 0x006f8d3b UIApplicationMain + 1225
16 TProduct 0x000070fd main + 141
17 libdyld.dylib 0x0224570d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是它无法识别的部分 GameViewController.m
-(void)changeViews:(NSString *)gameStateSegueIdentifier
{
NSLog(@"show view gameStateSegueIdentifier :%@",gameStateSegueIdentifier);
[self.containerController decideViewController:gameStateSegueIdentifier];
}
这就是我调用的方法 ContainerViewController.m
-(void)decideViewController:(NSString *)gameStateSegueIdentifier
{
if (gameStateSegueIdentifier == _currentSegueIdentifier) {
return;
}
while (gameStateSegueIdentifier != _currentSegueIdentifier) {
NSLog(@"this is the gameStateSegueIdentifier %@",gameStateSegueIdentifier);
NSLog(@"this is the currentSegueIdentifier %@",_currentSegueIdentifier);
[self changeViewControllers];
}
}
我知道已经有很多“无法识别的选择器发送到实例”问题。但到目前为止,我无法为我的案子找到答案。感谢您的帮助。
【问题讨论】:
-
添加日志消息以打印
self.containerController的值。该错误说它是UIViewController,而不是您认为应该是的任何子类。该属性是如何分配的? -
@PhillipMills,
2013-12-20 17:17:31.051 TProduct[8957:70b] value of the self.containerController <UIViewController: 0x8ad6520> and this is how the property is created in the GameViewController.m@property(nonatomic,weak)ContainerViewController *containerController;` -
这很简单。不知何故,您将指向 UIViewController 的指针转换为指向支持
decideViewController方法的某个类的指针。但 UIViewController 不支持该方法。大概指针是self.containerController,而你在初始化它时出错了。 -
@Matt 请注意,您向我展示了如何声明属性,而不是如何将对象分配给它。可能这里的关键区别......
-
@HotLicks,我实际上仍然对“不知何故”部分感兴趣。
@property (nonatomic,weak)ContainerViewController *containerViewController;因为当我 cmd+单击此属性时,我看到我的 containerviewclass 不是别的东西。只是为了确保我从另一个项目中复制了相同的代码,只是为了确保我没有忘记任何东西。但我仍然看到-[UIViewController decideViewController:]:
标签: ios objective-c unrecognized-selector