我在故事板中有一个图形控制器作为初始视图控制器。


如何返回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];我为什么要变成零?
发布于 2015-10-12 20:02:28
返回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];发布于 2019-01-09 06:52:31
在Swift中
let indexToRemove = 1
if indexToRemove < (self.viewControllers?.count)! {
var viewControllers = self.viewControllers
viewControllers?.remove(at: indexToRemove)
self.viewControllers = viewControllers
}直接在self类中使用UITabBarController,而不是self.tabBarControllers。
发布于 2016-06-08 11:02:48
看看乔的答案self.tabBarController is NULL
如果您有一个导航控制器,则需要将其添加到YourTabBarViewController.h文件中。
@property (nonatomic, retain) UITabBarController * myTabBarController;然后,在viewDidLoad中的YourTabBarViewController.m文件中,只需将其分配给self并添加委托即可。
self.myTabBarController = self;
self.myTabBarController.delegate = self;https://stackoverflow.com/questions/33088575
复制相似问题