Question

I'm trying to use a popover as an intermediary menu between my main view and a modal view controller. I can successfully present the Modal view controller from the popover by using the following code:

UIStoryboard *storyboardiPad = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
cbwEditControlPanel *editCP = [storyboardiPad instantiateViewControllerWithIdentifier:@"EditCP"];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editCP];
[nav setToolbarHidden:NO];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:nav animated:YES completion:nil];
self.modalInPopover = NO;

The problem I'm running into is that when the EditCP modal view controller is dismissed, the main view controller never updates. I have a pagecontroller on the main view that should be updated to reflect the number of pages as set in the EditCP modal view controller, but for some reason the modal view controller being called from the popover prevents the main view controller from updating the pagecontroller. I've even tried calling the main view's "View Will Appear" method from the popover or modal view when they are dismissed, but even if the 'viewWillAppear' method is called the pageController will not update!

Any ideas what is preventing the pageController from updating? I even passed a reference to the pagecontroller to the modal view and tried to update it there, but it seems that from the time the popover is presented until it is dismissed, I cannot update the number of pages on the PageController.

Thank you!

Was it helpful?

Solution 2

Well, I half solved the problem. The only way to get an update function when the popover disappeared was to stop using Storyboards and programmatically present the popover, using the main view as the delegate. I then was able to update correctly inside the popoverControllerDidDismissPopover method.

However, I am still interested in finding a way to update the pageControl when the modal is dismissed, before the popover is dismissed.

OTHER TIPS

So this is an old question but I also came across a similar problem recently when using a popover. My solution was to use an unwind segue to trigger my parent view to perform some action. In my case my parent view contains contact information and the popover contains a list of cites. All I wanted to do was to have the parent view update with the new city once the user selected it from the popover. So in my parent view I create my unwind function as follows:

In the .h:

- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue;

In the .m:

- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue
{
    [self updateTableForOffice];
}

In the above .m file is where you would have the logic to do whatever it is you want to in the parent view. To connect this unwind segue go to the child view in the storyboard and control drag from the view icon to the exit icon. You should see a pop up with the name of your unwind segue.

Finally, give that unwind segue a name and then in the child controller in the viewWillDisappear() function call the segue as follows:

- (void)viewWillDisappear:(BOOL)animated
{
    [self performSegueWithIdentifier:@"unwind-to-contact-tvc" sender:self];
}

I hope that helps. If someone has a better solution let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top