Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TabBarController返回null_Ios_Objective C_Null_Uitabbarcontroller - Fatal编程技术网

Ios TabBarController返回null

Ios TabBarController返回null,ios,objective-c,null,uitabbarcontroller,Ios,Objective C,Null,Uitabbarcontroller,我在故事板中有一个tabbarcontroller作为初始视图控制器 如何返回null UITabBarController* tabbarController = (UITabBarController*) self.tabBarController; NSLog(@"%@",tabbarController); NSLog(@"%@",self.navigationController.tabBarController); 最初我想做的是 NSMutableArray *newTabs

我在故事板中有一个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?

返回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];
看看乔的答案

如果您有导航控制器,则需要将其添加到您的TabBarViewController.h文件中

 @property (nonatomic, retain) UITabBarController * myTabBarController;
然后在viewDidLoad中的TabbarViewController.m文件中,将其分配给self并添加代理

self.myTabBarController = self;
self.myTabBarController.delegate = self;

Swift中

        let indexToRemove = 1
        if indexToRemove < (self.viewControllers?.count)! {
            var viewControllers = self.viewControllers
            viewControllers?.remove(at: indexToRemove)
            self.viewControllers = viewControllers
        }
让indexToRemove=1
如果indexToRemove<(self.viewControllers?.count)!{
var viewControllers=self.viewControllers
viewControllers?删除(位于:indexToRemove)
self.viewControllers=viewControllers
}

UITabBarController
类中直接使用
self
,而不是
self.tabBarControllers

此代码在哪里?调用的方法是什么?它在ViewDid出现后的
XCTabViewController.m
5秒内调用
[自执行选择器:@selector(delayed)with object:nil afterDelay:5]self
难道不是UITABBARC控制器吗?你是对的,而不是
self.tabBarController
Darn it。如果你发布一条你发现的好消息,我会接受答案。救了我