“发送到实例的无法识别的选择器”错误 [英] "Unrecognized selector sent to instance" error

查看:218
本文介绍了“发送到实例的无法识别的选择器”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AppDelegate代码的一部分是:

Part of my AppDelegate code is:

UITabBarController *tabBarController 
    = (UITabBarController *)self.window.rootViewController;

UINavigationController *navigationController 
    = [[tabBarController viewControllers] objectAtIndex:0];

PilotosViewController *playersViewController 
    = [[navigationController viewControllers] objectAtIndex:0];

playersViewController.drivers = players;

但是我得到了这个例外:

But I get this exception:


- [UIViewController viewControllers] :无法识别的选择器发送到实例0x6a75770

*** 终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [UIViewController
viewControllers]:无法识别的选择器发送到实例0x6a75770'

-[UIViewController viewControllers]: unrecognized selector sent to instance 0x6a75770
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController viewControllers]: unrecognized selector sent to instance 0x6a75770'

错误在哪里?

推荐答案

我遇到了同样的问题,因为我按照作者的步骤,但是

I met the same issue, because I followed the steps by the author, but

UINavigationController *navigationController 
    = [[tabBarController viewControllers] objectAtIndex:0];

这是导致崩溃的原因,因为 navigationController 不在 index = 0
我确实交换了两个标签栏项目的位置,然后就可以了。

this is what which made the crash, because navigationController is not at index=0, I did exchange the locations of the two tab bar items, then it works.

这篇关于“发送到实例的无法识别的选择器”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆