如何同时弹出模态视图和前一个导航控制器视图?

发布于 2024-12-15 07:54:14 字数 664 浏览 2 评论 0原文

我想同时弹出一个模态视图和上一个视图。例如,查看日历应用程序。当我在编辑屏幕上并选择删除事件时,我会返回到日历视图。

以模态方式呈现的编辑屏幕以及事件屏幕(用户仅在其中查看日历事件)都会弹出。我遇到的问题是我知道如何弹出模式视图,但是来自同一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

<逆流佳人身旁 2024-12-22 07:54:14

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

这正是日历应用程序上发生的情况 - 只需注意确认事件删除时导航栏标题发生的情况 - 您可以看到标题从“编辑”快速更改为“事件详细信息”,因为该视图正在弹出从导航堆栈中取出。

简而言之,如果我们正在谈论日历应用程序,则在您的模态视图控制器中,使用 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

- (void)didConfirmEventDeletion
{
    [self dismissModalViewControllerAnimated:NO];
    [self.navigationController popViewControllerAnimated:YES];
}

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:

@protocol ModalViewDelegate <NSObject>
- (void)didConfirmEventDeletion;
@end

@interface ModalViewController...

@property (nonatomic, assign) id<ModalViewDelegate> delegate;

@end     

And implementation:

@implementation ModalViewController

- (void)deleteEventMethod
{
    ...
    if ([self.delegate respondsToSelector:@selector(didConfirmEventDeletion)])
         [self.delegate 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: there might be a few typos as I wrote this code off memory...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文