如何同时弹出模态视图和前一个导航控制器视图?
我想同时弹出一个模态视图和上一个视图。例如,查看日历应用程序。当我在编辑
屏幕上并选择删除事件
时,我会返回到日历视图。
以模态方式呈现的编辑
屏幕以及事件
屏幕(用户仅在其中查看日历事件)都会弹出。我遇到的问题是我知道如何弹出模式视图,但是来自同一个 UIViewController 子类(本例中的“编辑”屏幕)。
如何弹出非模态视图?
我正在考虑像平常一样弹出模式视图,然后将 NSNotification
发布到“Event
”(例如)屏幕的 UIViewController
子类并告诉它也弹出该视图。
另一件事是,对于动画,它应该是 dismissModalViewControllerAnimated
动画(向下滑动),而不是 popViewControllerAnimated
动画(向左滑动)。
在寻找更好的解决方案时,我发现了 这个,它在我的情况下不起作用(至少不适用于 popViewControllerAnimated< /代码>。
I want to pop a modal view and the previous view at the same time. For example, look at the calendars app. When I am on the Edit
screen and select Delete Event
, I am taken back to the calendar view.
The Edit
screen, which was presented modally is popped as well as the the Event
screen (where the user is just viewing the calendar event). The problem I am having is that I know how to pop a modal view, but from the same UIViewController
subclass (Edit
screen in this example).
How can I pop a view that isn't modal?
I was thinking about popping the modal view as you would normally, then posting a NSNotification
to the 'Event
' (for instance) screen's UIViewController
subclass and telling it to pop that view as well.
The other thing is that for the animation, it should be the dismissModalViewControllerAnimated
animation (slide down) and not the popViewControllerAnimated
animation (slide left).
Looking for a better solution, I found this, which doesn't work in my case (at least not with popViewControllerAnimated
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用委托模式来通知模态“父级”它应该关闭模态视图控制器(动画:否)并将其自身从堆栈中弹出(动画:是)。
这正是日历应用程序上发生的情况 - 只需注意确认事件删除时导航栏标题发生的情况 - 您可以看到标题从“编辑”快速更改为“事件详细信息”,因为该视图正在弹出从导航堆栈中取出。
简而言之,如果我们正在谈论日历应用程序,则在您的模态视图控制器中,使用
didConfirmEventDeletion
之类的方法创建一个协议:并实现:
然后在您的父视图控制器中,将其自身声明为模式的委托并实现
didConfirmEventDeletion
:PS:当我在内存中写下这段代码时,可能会有一些拼写错误......
You need to use the delegate pattern to notify the modal "parent" that it should dismiss the modal view controller (animated:NO) and pop itself off the stack (animated:YES).
This is exactly what happens on the Calendar App - just pay attention to what happens to the navigation bar title when you confirm an event deletion - you can see the title quickly changing from "Edit" to "Event Details" as that view is being popped out off the navigation stack.
So in a nutshell, if we were talking about the calendar app, in your modal view controller, create a protocol with a method like
didConfirmEventDeletion
:And implementation:
Then in your parent view controller, declare itself as the delegate for the modal and implement
didConfirmEventDeletion
:PS: there might be a few typos as I wrote this code off memory...