IOS ViewController 导航路径 - 如何以编程方式向后导航

标签 ios uinavigationcontroller ios5 xcode-storyboard

我正在使用 IOS5 Storyboard。我的 View Controller 路径如下:

tabbarVC --> navigationVC-1 --> tableVC-1 --(via segue push)-> tableVC-2 --(via segue modal)-> navigationVC-2 --> tableVC-3

在 tableVC-3 的取消按钮回调操作方法中,我调用了 [self dismissViewControllerAnimated:YES completion:nil]; 成功让我回到了 tableVC-2。但是,当我尝试在调试器中向后检查导航路径时,我看不到从 navigationVC-2 访问 tableVC-2 的方法。我希望 navigationVC-2 保持到 tableVC-2 或 navigationVC-1 的链接,但它似乎没有。请在下面查看我的调试器输出。

有人可以解释导航层次结构以及如何以编程方式向后遍历链吗?

(gdb) po self
<tableVC-3: 0x6d33340>

(gdb) po (UIViewController*) [self navigationController]
<UINavigationController: 0x6d33560>

(gdb) po (UIViewController*)[[self navigationController] navigationController]
Can't print the description of a NIL object.

(gdb) po (UIViewController*)[[self navigationController] topViewController]
<tableVC-3: 0x6d33340>

(gdb) po (UIViewController*)[[self navigationController] presentingViewController]
<UITabBarController: 0x6b2eba0>

(gdb) po (UIViewController*)[[self navigationController] presentedViewController]
Can't print the description of a NIL object.

(gdb) po (UIViewController*)[[self navigationController] visibleViewController]
<tableVC-3: 0x6d33340>

最佳答案

这是一个老问题,但为了帮助其他遇到此问题的人,有一个命令可以让您的生活更轻松..

[self.navigationController popToRootViewControllerAnimated:TRUE];

当您偶然发现正确的命令时很容易,不是吗!

因此,假设您在导航 Controller 中有一系列的三个屏幕,并且在第三个​​屏幕上您希望“后退”按钮将您带回初始 屏幕。

-(void)viewDidLoad
{
    [super viewDidLoad];

    // change the back button and add an event handler
    self.navigationItem.leftBarButtonItem =
    [[UIBarButtonItem alloc] initWithTitle:@"Back"
                                     style:UIBarButtonItemStyleBordered
                                    target:self
                                    action:@selector(handleBack:)];
}


-(void)handleBack:(id)sender
{
    NSLog(@"About to go back to the first screen..");
    [self.navigationController popToRootViewControllerAnimated:TRUE];
}

关于IOS ViewController 导航路径 - 如何以编程方式向后导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8697501/

相关文章:

iphone - 使用 ios5 操作系统和 ios5 sdk 提交 ios 应用程序

android - 如何设置平台以开发具有 Windows 和 Java 知识的 iOS 应用程序

ios - UITabBarController + UINavigationController 和更多选项卡黑屏问题

适用于hidesBottomBarWhenPushed的iOS自定义动画

ios - 权利无效?

ios5 - 使用 autoresizingmask 的 UIView 水平居中不起作用

ios - NSString 的内存管理问题

ios - 如何将特定的 UITableView 行发送到特定的 ViewController?

ios - 在 dispatch_async 中设置属性,但 block 完成后属性为 NULL

ios - 如何检测在 popViewController 函数覆盖上弹出哪个 ViewController?