重新呈现模态视图带来最后一个 VC 而不是第一个
我有一个导航控制器,它在堆栈中以 4 个视图的形式呈现。最终视图有一个完成按钮,可以关闭模式视图。当我再次呈现模态视图时,它会自动转到最后一个视图而不是第一个视图。我添加了一行以在关闭后弹出到第一个视图,但无论我将其设置为“是”还是“否”,它都会添加一个奇怪的动画。也许我做错了?
- (void)dismissModalView
{
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -4)] animated:YES];
}
更新:
这是用于呈现模式视图/导航控制器的方法
- (void)showModalView
{
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:self.optionsNavController animated:YES];
}
I have a Navigation Controller that is presented modally with 4 views in the stack. The final view has a done button that dismisses the modal view. When I then present the modal view again, it automatically goes to that last view instead of the first one. I added a line to pop to first view after dismissed but it adds a weird animation whether I set it to YES or NO. Maybe I'm doing it wrong?
- (void)dismissModalView
{
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count] -4)] animated:YES];
}
Update:
This is the method used to present the modal view/navcontroller
- (void)showModalView
{
self.optionsNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentModalViewController:self.optionsNavController animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我过于简单化了您的问题,请原谅,但是如果您需要直接弹回第一个视图控制器,也许您可以尝试使用
popToRootViewControllerAnimated:
方法,而不是popToViewController:< /代码>。
Excuse me if I'm oversimplifying your issue, but if your need is to pop straight back to the first view controller, perhaps you could give the
popToRootViewControllerAnimated:
method a try instead ofpopToViewController:
.我不确定您发布的驳回代码有什么问题,但以下内容应该有效:
此外,
viewDidLoad
旨在每次加载视图时仅调用一次,viewWillAppear
一个I'm not sure what the problem with the dismiss code you posted is, but the following should work:
Also,
viewDidLoad
is intended to only be called once every time the view is loaded,viewWillAppear
a不,看起来不错。如果您想保留导航控制器的状态,则不要以模态方式呈现它,因为当您关闭视图时它将被释放。
模态视图通常用于呈现只需要简单显示而无需维护视图状态的信息(即关于页面、登录页面、设置页面等)。
No, it looks right. If you want to retain the state of the Navigation controller then don't present it modally as it will get deallocated when you dismiss the view.
Modal views are usually used to present information that only needs to be shown briefly without maintaining the state of the view (i.e. about page, login page, settings page, etc).