3
votes

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?

2
I tried to drag my tab bar item to perform a segue to my other view controller but it doesn't let meAyush

2 Answers

2
votes

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
votes

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!