iOS: Implementing UITabBar from User Interface without a UITabBarController
In my app I开发者_如何学C have a UIViewController to which I wish to add a UITabBar. So I have added it via User Interface (into the UIViewController.xib file) and created instances of the IUTabBar and the UITabBarItems within the UIViewController.h+m files. in the xib file I was able to connect the code items to the ones on the xib (by dragging from the File Owner to the relevant item and selecting the relevant IBOutlet) but I cannot seem to connect back the buttons to the IBActions written on the h+m files.
Before adding the UITabBar I worked with a UIToolBar and had no problem doing these connections.
Can anyone explain what am I doing wrong?
You should implement the UITabBarDelegate
protocol (documentation here).
Once you are implementing this protocol, just use the - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
method to know when a user changes the selected item of a tab bar. In this method's implementation, you will have to check which item is selected, and manually change your view's content based on that.
// Disable this
UITabBarController.tabbar.userInteractionEnabled = NO;
// Enable this
UITabBarController.tabbar.userInteractionEnabled = YES;
精彩评论