iPhone - 关闭父模态视图

发布于 2024-09-09 08:17:56 字数 1106 浏览 3 评论 0原文

我正在勾画一个应用程序的工作流程,其中有一个主菜单“级别 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小糖芽 2024-09-16 08:17:56

我会为 2 级控制器创建一个协议,例如 Level2Delegate。然后将二级控制器的委托设置为一级控制器。然后您可以执行如下操作:

2 级控制器将实现此功能,其中 self.delegate 是 1 级控制器

[self.delegate controllerDidFinish:self];

将实现的 1 级控制器:

- (void)controllerDidFinish:(Level2Controller *)controller {
    [[self parentViewController] dismissModalViewControllerAnimated:NO];
}

关键是设置事件链,而不是尝试立即消除这两个事件。

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

[self.delegate controllerDidFinish:self];

Level 1 would implement:

- (void)controllerDidFinish:(Level2Controller *)controller {
    [[self parentViewController] dismissModalViewControllerAnimated:NO];
}

The key is to set up a chain of events rather than trying to dismiss both at once.

冬天的雪花 2024-09-16 08:17:56

为什么不使用,

[self.navigationController popToRootViewControllerAnimated:YES];

Why not using,

[self.navigationController popToRootViewControllerAnimated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文