问题
I have a a VC structure like this
UIPageViewController -> detailViewController -> popoverviewcontroller
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.
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];
}
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.
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?
回答1:
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.
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.
When you push a controller it will message isMovingToParentViewController
when shown and isMovingFromParentViewController
when dismissed, again in the controller being presented.
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.
来源:https://stackoverflow.com/questions/64581143/how-do-i-display-an-alert-over-a-pageviewcontroller-after-a-popover-dismissal