Ritika
Ritika

Reputation: 593

Programmatically switch UItabbarcontroller index & customize

From a button inside first viewcontroller of UItabbarcontroller, I want to switch tabbar controller programatically to a second tab index.

self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];

I also want to change the text of UILabel, which is within xib of second viewcontroller. How can I do that?

When I access the selectedViewController's IBOutlet there are all null.

Upvotes: 1

Views: 958

Answers (1)

120hit
120hit

Reputation: 1026

Use this method : 1:

//for navigation

[self.tabBarController.navigationController popToRootViewControllerAnimated:YES ];


     [self.tabBarController setSelectedViewController:[self.tabBarController.viewControllers objectAtIndex:1]];

2:

 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

set label by :

for (UIView* subview in [[[self.tabBarController.viewControllers objectAtIndex:1] view] subviews] )
{
    if (    [subview isKindOfClass:[UIlabel class]] )
    {
        // do here
        break;
    }
}

This may help you...

Upvotes: 2

Related Questions