我正在使用 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/