Remove UITabBarItem

How to remove UITabBarItemfrom UITabBar?

I have not tried anything because I have not found anything from Google searches or the documentation for UITabBar, UITabBarControlleror UITabBarItem.

Thanks in advance!:)

+5
source share
3 answers

UITabBar has a collection of NSArray items . Since the items property is an NSArray, not an NSMutableArray , you will need to create a new NSArray from an existing, deprived object that you want to delete, and then set the items property to a new array.

/* suppose we have a UITabBar *myBar, and an int index idx */
NSMutableArray *modifyMe = [[myBar items] mutableCopy];
[modifyMe removeObjectAtIndex:idx];
NSArray *newItems = [[NSArray alloc] initWithArray:modifyMe];
[myBar setItems:newItems animated:true];
+9
source

, tabBar, .

iOS 3.0 , . . . , .

self.tabBarItem=nil .

+4

: iOS 11 . iOS 10 .

, , , , - , :

UITabBar *oldbar = self.tabBarController.tabBar;
UITabBar *newbar = [[UITabBar alloc] initWithFrame:CGRectMake(0,0,oldbar.frame.size.width,oldbar.frame.size.height)];
NSMutableArray *olditems = [[oldbar items] mutableCopy];
[olditems removeObjectAtIndex:0];
NSArray *newitems = [[NSArray alloc] initWithArray:olditems];
[newbar setItems:newitems animated:false];
[oldbar addSubview:newbar];

This completely cleans the top panel of the old panel and supports its functionality.

0
source

All Articles