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

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

问题描述

我在google或堆栈溢出时没有发现类似的东西...

I haven't found anything similar to this on google or stack overflow...

我要做的是弹出模态视图和之前的同时查看。例如,查看日历应用。当您进入编辑屏幕并选择删除事件时,您将被带回日历视图。弹出了以模拟方式显示的编辑屏幕以及事件屏幕(其中用户只是查看日历事件)。我遇到的问题是我知道如何弹出模态视图......但来自相同的 UIViewController 子类('编辑此示例中的屏幕,如何弹出非模态的视图

What I'm trying to do is pop a modal view and the previous view at the same time. For example, look at the calendars app. When you are on the 'Edit' screen and select 'Delete Event', you are 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 do I pop a view that isn't modal?

我正在考虑弹出正常情况下的模态视图,然后将 NSNotification 发布到'事件'(例如)屏幕的 UIViewController 子类并告诉它也可以弹出该视图。

I was thinking about popping the modal view as you would normally, then posting an 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).

谢谢。

此外,寻找比这个,在我的情况下不起作用(在l东不与 popViewControllerAnimated

Also, looking for a better solution than 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.

简而言之,如果我们在讨论日历应用程序时,在模态视图控制器中,使用类似<的方法创建协议code> 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天全站免登陆