弹出窗口关闭后,如何在 PageViewController 上显示警报? [英] How do I display an alert over a PageViewController after a popover dismissal?

查看:71
本文介绍了弹出窗口关闭后,如何在 PageViewController 上显示警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的 VC 结构

I have a a VC structure like this

UIPageViewController ->detailViewController ->弹出视图控制器

UIPageViewController -> detailViewController -> popoverviewcontroller

使用 unwind segue 关闭 popoverviewcontroller,将我们带回 detailviewcontroller

The popoverviewcontroller is dismissed using an unwind segue, bringing us back to the detailviewcontroller

现在,在弹出窗口被解除后,我想刷新页面控制器上的页面,因为用户采取的操作已经改变了数据.

Now, after the popover is done being dismissed, I would like to refresh the pages on the pagecontroller, since the action the user takes has changed the data.

我还想显示一个提醒,通知用户他们是否成功.

I would also like to display an alert notifying the user about whether they were successful.

所以我试着把这段代码放在 pageViewcontroller 中

So I tried putting this code in the pageViewcontroller

- (IBAction) unwindFromPopup:(UIStoryboardSegue*)unwindSegue{
    [self refreshPages];
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"this should appear" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertController animated:YES completion:nil];
}

我尝试将上述代码移至详细信息视图控制器,但没有得到任何结果.没有错误或任何东西,只是完全缺乏警觉.我在 segue 中放置了一个断点,然后代码被调用.但没有警报.

I tried moving the above code to the detail view controller instead, but I am getting no result from this. No error or anything, just a complete lack of alert. I put a breakpoint in the segue, and the code gets called. But no alert.

我想将代码放在各自的 viewDidAppear 方法之一中,但由于某种原因,在我关闭弹出窗口后,viewDidAppear 不会被 pageviewcontroller 或 detailview 控制器调用.

I thought of putting the code in one of the respective viewDidAppear methods, but for some reason viewDidAppear does not get called for either the pageviewcontroller or the detailview controller after I dismiss the popup.

所以此时我不知道如何显示此警报.

So at this point I have no idea how to make this alert appear.

我是否需要发布我的完整代码,或者我的问题是否与我所包含的详细信息有关?

Do I need to post my full code, or is my problem apparent with the details I've included?

推荐答案

谢谢 - 根据您的评论...很久以前,在一个遥远的 iOS 版本中,我执行了所有可能的 segue 并记录了什么时候被调用并有一个表我的回答基于这一点.我必须承认,现在我使用演示控制器委托完成了大部分工作.

Thanks - based on your comment ... long ago in a distant version of iOS I performed all the possible segues and noted what gets called when and have a table of that that I based my answer on. I must admit, nowadays I get most done using the presentation controller delegate.

无论如何,为了回答您的问题,当您弹出或以模态呈现控制器时,正在呈现的控制器将消息 beingPresentedbeingDismissed 完成后,您可能可以将其用于您尝试执行的操作.

Anyhow, to reply to your question, when you pop or modally present a controller, the controller that is being presented will message beingPresented and beingDismissed when it is done and you might be able to use this for what you are trying to do.

当您推送一个控制器时,它会在显示时显示 isMovingToParentViewController 消息,在关闭时显示 isMovingFromParentViewController 消息,再次在显示的控制器中.

When you push a controller it will message isMovingToParentViewController when shown and isMovingFromParentViewController when dismissed, again in the controller being presented.

回到弹出窗口......它会在呈现的 VC 和 viewWillAppearviewDidAppear 在呈现的 VC 中发送消息 prepareForSegue 并且,当解除,将在所呈现的 VC 中发送 only viewWillDisappearviewDidDisappear 消息,因此您的问题.至少它还会像提到的那样发送 beingDismissed 消息,如果你能使用它,我真的很为你高兴.

Back to a pop ... it will message prepareForSegue in the presenting VC and viewWillAppear and viewDidAppear in the presented VC and, when dismissing, will message only viewWillDisappear and viewDidDisappear in the presented VC, thus your problem. At least it will also message beingDismissed as mentioned and if you can use that I am really glad for you.

这篇关于弹出窗口关闭后,如何在 PageViewController 上显示警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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