mpp*_*dev 4 uinavigationcontroller ios ios5 xcode-storyboard
我正在使用IOS5 Storyboard.我的视图控制器路径如下:
tabbarVC --> navigationVC-1 --> tableVC-1 --(via segue push)-> tableVC-2 --(via segue modal)-> navigationVC-2 --> tableVC-3
Run Code Online (Sandbox Code Playgroud)
在表VC-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>
Run Code Online (Sandbox Code Playgroud)
这是一个老问题,但只是为了帮助遇到这个问题的其他人,只需要一个命令就可以让你的生活更轻松.
[self.navigationController popToRootViewControllerAnimated:TRUE];
Run Code Online (Sandbox Code Playgroud)
当你偶然发现正确的指令时很容易,不是吗!
因此,假设您在导航控制器中有一系列三个屏幕,并且在第三个屏幕上,您需要"返回"按钮将您带回初始屏幕.
-(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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20225 次 |
| 最近记录: |