开发者

iOS: Implementing UITabBar from User Interface without a UITabBarController

开发者 https://www.devze.com 2023-03-22 16:07 出处:网络
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 an

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;
0

精彩评论

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

关注公众号