问题
I’ve created a StoryBoard project and added a UITabBar to my first view and a few UITabBar items on it. I’m using a UITabBar and not a UITabBarController because the UITabBar needs to be scrollable vertically so it is inside a UIScrollView. I want to connect the UITabBar items to different ViewControllers. How do I do that inside the Interface builder?
With UITabBarController it’s just a Ctrl+drag like everything else in the IB, but for some reason the UITabBar acts differently. I’m aware of all the delegation methods I need to implement, but for now I’m only interested on how to connect the UITabBar items to the views.
回答1:
What you're probably after is UITabBarController.
You generally don't want to manage a UITabBar manually.
If you're using storyboards, you can drag out a UITabBarController and then Ctrl-drag from it to other view controllers in the storyboard to link them to the viewControllers property.
回答2:
Try:
firstViewController.tabBarItem = firstItem;
回答3:
- From
UITabBaritem ctr+drag to your nextViewController(select style push, modal). - Give you
UITabbarItemtags. - Import
UITabBarDelegateto your Controller. Add following delegate method
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { if (item.tag==0) { [self performSegueWithIdentifier:@"Favorite" sender:nil]; } else if (item.tag==1) { [self performSegueWithIdentifier:@"Item" sender:nil]; } }- Give identifier for each segue.
you can get my demo from following link
but problem is that tabbar will not appear on next ViewController
来源:https://stackoverflow.com/questions/16962043/how-do-i-connect-uitabbar-items-from-a-uitabbar-not-a-uitabbarcontroller-to-di