如何从一个uitabbarcontroller弹出到另一个uitabbarcontroller

时间:2014-02-06 12:18:29

标签: ios uinavigationcontroller uitabbarcontroller

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

}

上面提到的是我在tabcontroller 1的vc4上做的事情

这是我的情景:

Tabcontroller1 vc1 - vc2 - vc3 - vc4

Tabcontroller2 vc1 - vc4(tabcontroller 1)

现在当我从vc4弹出时我想来vc1(tabcontroller 2) 当我想要去tabcontroller 2的vc1到tabcontroller 1的vc4时

请帮帮我。

1 个答案:

答案 0 :(得分:1)

您不应使用UINavigationController更改UITabBarController中的标签。

如果您想更改标签,则应获取UITabBarController的实例并使用:

tabBarController.selectedIndex = desiredIndex;

这里有一个来自我的项目的示例代码(我使用一些动画):

- (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];
}