假如你是使用storyboard上构建的tabbarcontroller,TabbarController上有3个item这时候你想在代码里动态变更成2个,保留第一个和第三个,去掉中间一个,怎么办?
只需要用以下代码就搞定了:
UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [tabBarController viewControllers]];
[tabbarViewControllers removeObjectAtIndex:1];
[tabBarController setViewControllers: tabbarViewControllers ];