我想同时弹出一个模态视图和上一个视图.例如,查看日历应用程序.当我在 Edit
屏幕上并选择 Delete Event
时,我将返回日历视图.
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.
Edit
屏幕和 Event
屏幕(用户只是在其中查看日历事件)以模态方式显示.我遇到的问题是我知道如何弹出模态视图,但来自同一个 UIViewController
子类(本例中为 Edit
屏幕).
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).
如何弹出非模态视图?
我正在考虑像往常一样弹出模式视图,然后将 NSNotification
发布到Event
"(例如)屏幕的 UIViewController
子类并告诉它也弹出该视图.
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.
另外,对于动画来说,应该是dismissModalViewControllerAnimated
动画(向下滑动)而不是popViewControllerAnimated
动画(向左滑动).
The other thing is that for the animation, it should be the dismissModalViewControllerAnimated
animation (slide down) and not the popViewControllerAnimated
animation (slide left).
寻找更好的解决方案,我发现 this,这在我的情况下不起作用(至少对于 popViewControllerAnimated
.
Looking for a better solution, I found this, which doesn't work in my case (at least not with popViewControllerAnimated
.
您需要使用委托模式通知模态父级"它应该关闭模态视图控制器(动画:NO)并将自己从堆栈中弹出(动画:是).
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.
所以简而言之,如果我们在谈论日历应用程序,在您的模态视图控制器中,使用 didConfirmEventDeletion
之类的方法创建一个协议:
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
:
@protocol ModalViewDelegate <NSObject>
- (void)didConfirmEventDeletion;
@end
@interface ModalViewController...
@property (nonatomic, assign) id<ModalViewDelegate> delegate;
@end
及实施:
@implementation ModalViewController
- (void)deleteEventMethod
{
...
if ([self.delegate respondsToSelector:@selector(didConfirmEventDeletion)])
[self.delegate didConfirmEventDeletion];
}
然后在您的父视图控制器中,将自己声明为模态的委托并实现 didConfirmEventDeletion
:
Then in your parent view controller, declare itself as the delegate for the modal and implement didConfirmEventDeletion
:
- (void)didConfirmEventDeletion
{
[self dismissModalViewControllerAnimated:NO];
[self.navigationController popViewControllerAnimated:YES];
}
PS:我写这段代码时可能有一些拼写错误...
PS: there might be a few typos as I wrote this code off memory...
这篇关于如何一次弹出模态视图和前一个导航控制器视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!