Abhishek
Abhishek

Reputation: 368

how to pop from one uitabbarcontroller to another

-(void)backButtonclicked
{
    ViewController *rvc = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
    [self.navigationController popToViewController:rvc animated:YES];

}

above mentioned is what I am doing at vc4 of tabcontroller 1

this is my scenario :

Tabcontroller1 vc1 - vc2 - vc3 - vc4

Tabcontroller2 vc1 - vc4(of tabcontroller 1)

now when I am popping from vc4 I want to come at vc1 (of tabcontroller 2) and when pushing I want to go to vc1 of tabcontroller 2 to vc4 of tabcontroller 1

please help me out.

Upvotes: 0

Views: 245

Answers (1)

Szu
Szu

Reputation: 2252

You shouldn't use UINavigationController to change tab in UITabBarController.

If you want to change tab you should get instance of UITabBarController and use:

tabBarController.selectedIndex = desiredIndex;

Here you have an example code from my project (i do it with some animations):

- (IBAction)mapButtonTapped:(UIBarButtonItem *)sender {
    UIView *startView = self.tabBarController.selectedViewController.view;
    UIView *endView = ((UIViewController *)[self.tabBarController.viewControllers objectAtIndex:ELMapViewControllerIndex]).view;
    [UIView transitionFromView:startView toView:endView duration:ELAnimationDuration
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    completion:^(BOOL finished) {
                        if (finished)
                            self.tabBarController.selectedIndex = ELMapViewControllerIndex;
                    }];
    ELMainMapViewController *carparkVC = [self.tabBarController.viewControllers objectAtIndex:ELMapViewControllerIndex];
    MKCoordinateRegion region = [self.delegate locationCoordinateForTappedMapButton];
    [carparkVC moveToRegion:region];
}

Upvotes: 1

Related Questions