繁体   English   中英

应用程序崩溃,错误无法识别的选择器发送到实例

[英]App crashes with error unrecognized selector sent to instance

我有一个无法识别的选择器发送到实例问题。 我知道哪条线路有问题,但我不明白为什么它不能识别它。 (我在创建容器视图时测试了这段代码,它运行得很好。但是出于某种原因,当我将它合并到我的主项目时,我收到了这个错误。)

这是我的控制台输出:

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];
    }
}

我知道有很多“无法识别的选择器发送到实例”问题已经存在。 但到目前为止,我无法找到答案。 我很感激帮助。

您收到的错误消息解释了问题:

2013-12-20 16:47:59.633[8545:70b] -[UIViewController decideViewController:]: unrecognized selector sent to instance 0x8b5c250

这告诉你类UIViewController一个实例得到了消息decideViewController: . UIViewController不响应此消息。 因此,似乎self.containerController是一个UIViewController而不是ContainerViewController (如果它是一个ContainerViewController ,它会在错误消息中这样说。)

该属性声明为ContainerViewController这一事实并不意味着其中实际上有一个ContainerViewController。 转到实际创建此对象的位置并将其分配给该属性,并确保将其创建为正确的类。

当无法识别选择器时,您不需要显示选择器的代码,因为它不会被执行。

显示containerController的属性行。

  1. 你是100%确定self.containerController是一个ContainerViewController,你的错误信息显示了一个UIViewController ,所以你正在做一些特殊的事情,如集群或类别?

  2. 你在使用#import“ContainerViewController”吗?

  3. @implementation @end部分中的方法是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM