Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 794
Ayush Avatar asked Feb 03 '26 17:02

Ayush


1 Answers

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!

like image 139
Maria Camila Alvarez Avatar answered Feb 05 '26 06:02

Maria Camila Alvarez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!