【发布时间】:2011-03-24 09:26:58
【问题描述】:
是否可以有效地关闭 2 个视图控制器?
我目前有 3 个 viewController
View1 > 呈现 View2 , View2 > 呈现 View3,然后当在 View3 中触发动作时,我需要返回到 View1 的 Viewcontroller。
在不创建新的 View1 对象的情况下如何做到这一点?
【问题讨论】:
是否可以有效地关闭 2 个视图控制器?
我目前有 3 个 viewController
View1 > 呈现 View2 , View2 > 呈现 View3,然后当在 View3 中触发动作时,我需要返回到 View1 的 Viewcontroller。
在不创建新的 View1 对象的情况下如何做到这一点?
【问题讨论】:
[self.navigationController popToRootViewControllerAnimated:YES];
或者
int index=[[self.navigtionController viewControllers] indexOfObject:self]-2;
//make sure index is within the range of the array otherwise it will do bad things.
UIViewController *vc=[[self.navigationController viewControllers] objectAtIndex:index];
[self.navigationController popToViewController:vc animated:YES];
可以使用
【讨论】:
由于它们都是模态呈现的,最好的办法可能是将 view2 设置为 view3 的委托,以便 View3 可以调用将关闭 view3 和 view2 的委托方法。
【讨论】: