返回上一个ViewController

时间:2013-06-18 09:20:48

标签: uiviewcontroller uitabbarcontroller

我在Xcode中有一个标签式应用程序项目,我正在尝试为其中一个viewcontrollers创建一个后退按钮,以便返回上一个视图。您可以从2个不同的viewcontroller获取此viewcontrollers,因此我想知道是否可以弹出viewcontroller以便返回正确的视图控制器(您之前使用的那个)上)。此代码似乎不适用于tabBarController

-(IBAction) goBack: (id)sender{
[self.tabBarController popViewControllerAnimated: YES]; }

3 个答案:

答案 0 :(得分:0)

NSArray *array = [self. tabBarController viewControllers];

[self.tabBarController popToViewController:[array objectAtIndex:2] animated:YES];

认为这个有效。没有测试过它。请让我知道

答案 1 :(得分:0)

检查一下。

id controller = [self.tabBarController selectedViewController];
        if([controller isKindOfClass:[UINavigationController class]])
        {
            [controller popViewControllerAnimated:YES];
        }

答案 2 :(得分:0)

NSArray *array = [self. tabBarController viewControllers];
for (UIViewController *controller in array) {
    if ([controller isKindOfClass:[ReachViewControllerName class]]) {
        [self.navigationController popToViewController:controller
                                              animated:YES];
        break;
    }
}

可能会有所帮助。

相关问题