我在故事板中有一个tabbarcontroller作为初始视图控制器
这是如何返回null的
UITabBarController* tabbarController = (UITabBarController*) self.tabBarController; NSLog(@"%@",tabbarController); NSLog(@"%@",self.navigationController.tabBarController);
本来就是我想要做的
NSMutableArray *newTabs = [NSMutableArray arrayWithArray:[self.tabBarController viewControllers]]; NSLog(@"\n\n\n%lu\n\n\n",(unsigned long)[newTabs count]); NSLog(@"self.tabBarController.viewControllers %@ \n\n",self.tabBarController); [newTabs removeObjectAtIndex: 1]; [self.tabBarController setViewControllers:newTabs];
为什么我会变空?
解决方法
返回null的原因是self是你的UITabBarController,因此,它在self.tabBarController上没有任何东西
您的代码应如下所示:
NSMutableArray *newTabs = [NSMutableArray arrayWithArray:[self viewControllers]]; NSLog(@"\n\n\n%lu\n\n\n",(unsigned long)[newTabs count]); NSLog(@"self.viewControllers %@ \n\n",self); [newTabs removeObjectAtIndex: 1]; [self setViewControllers:newTabs];
原文地址:https://www.jb51.cc/iOS/328461.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。