I’m trying to add a UIButton to UITabBar in my iPad application with following code:
TabBarAppDelegate *delegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate];
UITabBarController *tabbar = (UITabBarController *)delegate.window.rootViewController;
UIButton *b = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[tabbar.view addSubview:b];
tabbar is OK and referencing to a correct tabbar item (say, I can switch active tab with following code: [tabbar setSelectedIndex:1];).
This code is called by some other custom button. Though there are no errors in the log, the button doesn’t show on the tabbar 🙁
What am I doing wrong and what is a right way to add UIButton to UITabBar? 🙂 Here is an example:
http://gyazo.com/99fc0df0ed47dd6be91b558161cab4f9.png
Thanks in advance!
Edit: OK, if I’ll stick to UIToolbar option, then what is a right way to switch between views? Create an NSArray of ViewContollers and load corresponding ViewController’s view to an active View?
You cannot add a
UIButtondirectly to aUITabBarController. From theUITabBarControllerClass Reference:Further along, the documentation reads:
Therefore your two options are:
UITabBarItem(documentation) and add that.UIToolBarinstead, but remember to addUIBarButtonItems.