如何一次弹出模式视图和上一个导航控制器视图? [英] How can I pop a modal view and the previous navigation controller view at once?

查看:83
本文介绍了如何一次弹出模式视图和上一个导航控制器视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时弹出一个模式视图和上一个视图.例如,查看日历应用程序.当我在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).

寻找更好的解决方案,我发现了,在我的情况下不起作用(至少在.

Looking for a better solution, I found this, which doesn't work in my case (at least not with popViewControllerAnimated.

推荐答案

您需要使用委托模式来通知模式父级"它应该关闭模式视图控制器(动画:否)并自动将其弹出堆栈(动画:是).

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...

这篇关于如何一次弹出模式视图和上一个导航控制器视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆