iPhone - 关闭父模态视图
我正在勾画一个应用程序的工作流程,其中有一个主菜单“级别 0”,它调用模态视图“级别 1”,它调用另一个模态视图“级别 2”。
我能够让这个工作正常进行,没有问题,并且我能够通过使用以下方式关闭整个堆栈:
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];
在模态视图“Level 2”中。
我的问题是,当模态视图“Level 2”有导航栏时,我无法关闭整个堆栈。我上面列出的代码仅使我返回一级,因此它的行为实际上与我执行此操作相同:
[self dismissModalViewControllerAnimated:YES];
在模态视图“级别 2”上。
概括: 当模态视图“级别 1”使用以下命令调用模态视图“级别 2”时:
Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];
[self presentModalViewController:portalMainController animated:YES];
我可以关闭整个堆栈并返回主菜单(级别 0)。但是,当“1 级”通过导航栏调用“2 级”时,如下所示:
Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:level2];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
我无法返回“0 级”,只能返回“1 级”。
有什么建议吗?
I am sketching out the workflow of an app where you have a main menu 'Level 0' that calls a modal view 'Level 1', which calls another modal view 'Level 2'.
I am able to get this working, no problem AND I am able to dismiss the entire stack by using:
[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES];
in the modal view 'Level 2'.
My problem is when modal view 'Level 2' has a navigation bar I cannot dismiss the entire stack. The code I listed above only brings me back one level so it really acts the same as if I had done this:
[self dismissModalViewControllerAnimated:YES];
on modal view 'Level 2'.
Summary:
When modal view 'Level 1' calls modal view 'Level 2' using the following:
Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];
[self presentModalViewController:portalMainController animated:YES];
I can dismiss the entire stack and get back to the main menu (Level 0). BUT when 'Level 1' calls 'Level 2' with a navigation bar like the following:
Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:level2];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
I cannot get back to 'Level 0', I only get back to 'Level 1'.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会为 2 级控制器创建一个协议,例如 Level2Delegate。然后将二级控制器的委托设置为一级控制器。然后您可以执行如下操作:
2 级控制器将实现此功能,其中 self.delegate 是 1 级控制器
将实现的 1 级控制器:
关键是设置事件链,而不是尝试立即消除这两个事件。
I would create a protocol for the level 2 controller such as Level2Delegate. Then set the delegate of the level 2 controller to be the level 1 controller. Then you could do something like the following:
Level 2 controller would implement this where self.delegate is the level 1 controller
Level 1 would implement:
The key is to set up a chain of events rather than trying to dismiss both at once.
为什么不使用,
Why not using,