is it possible to perform a segue from tab bar item?

百般思念 提交于 2020-01-05 02:59:05

问题


I used a UIview controller for my app home page and then added a tab bar at the bottom just like Facebook and then added 3 more tab bar item, it doesn't let me perform a segue when drag the tab bar item to a View Controller, is it possible progmatically or in storyboard?


回答1:


Simple: You need a UITabViewController, tab bar items can't be used the way you're asking for.

Ctrl+drag from your tabview controller to a view you'd like to include (Third in this case)

You then select the view controllers option to add the relationship segue.




回答2:


I had the same problem, but i couldn't find a way to assign to a viewController its own viewControllers as in the TabViewController case.

I solved it using containers. One container for each tabBarItem in your tabBar, which are hidden or showed depending of the selected tabBarItem in the tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item method.

1. Create your containers in your UIviewController in storyBoard: Just like this Select your tabBar and Ctrl+Drag to delegate the class for listen the tabBarDelegate methods: look here

2. Declare the corrisponging IBOutlets, incliding your tabBAr:

#import <UIKit/UIKit.h>

@interface TabsMainViewController : UIViewController

@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@property (strong, nonatomic) IBOutlet UIView *directoryContainer;
@property (strong, nonatomic) IBOutlet UIView *groupsContainer;
@end

3. Select the container to show in the tabBarDelegate method:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {

            switch (item.tag) {
            case 1:
                _directoryContainer.hidden = NO;
                _groupsContainer.hidden = YES;
             break;

            case 2:
                _directoryContainer.hidden = YES;
                _groupsContainer.hidden = NO;
                break;

            default:
                break;
        }

    }

Hope that helps!



来源:https://stackoverflow.com/questions/31278709/is-it-possible-to-perform-a-segue-from-tab-bar-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!