开发者

Hide or remove a tab in tab based application in Xcode

开发者 https://www.devze.com 2022-12-14 06:15 出处:网络
I am very new to iP开发者_如何学Pythonhone and Xcode. I am trying to create a tab-based application, in that from the first page, when a button is clicked, I need to remove/hide some of the tabs added

I am very new to iP开发者_如何学Pythonhone and Xcode. I am trying to create a tab-based application, in that from the first page, when a button is clicked, I need to remove/hide some of the tabs added in the tab bar.

Can any one help me out please.

Thanks and Regards, Bala.


Let's say you want to remove the fourth tab from the tab bar (tab index == 3). Just modify the tabbar controller's viewControllers array accordingly:

NSUInteger indexToRemove = 3;
NSMutableArray *controllersToKeep = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
UIViewController *removedViewController = [[controllersToKeep objectAtIndex:indexToRemove] retain];
[controllersToKeep removeObjectAtIndex:indexToRemove];
[tabBarController setViewControllers:controllersToKeep animated:YES];

Note that if you want to keep the removed/hidden view controller around in the background, it's essential that you retain it before removing it from the tab bar (see line 3).

0

精彩评论

暂无评论...
验证码 换一张
取 消