1
votes

I'm trying to get a popover to dismiss itself when I click a button, but it doesn't seem to be working. I know there are a few questions regarding this, but I think my set up is slightly different. In storyboards I have the following setup:

View Controller -> (segue popover) -> View Controller 2

View Controller 2 has a "Done" button linked to an IBAction as follows:

- (IBAction)returnCommand:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

I know that you can click outside of the popup to dismiss it, but I want to do a few other things when Done is pressed. With this code, nothing happens when I click the "done" button.

2
You need to send a message to View Controller 1 that the operations are done. View Controller 1 should then dismiss the popover. - Aaron Brager

2 Answers

1
votes

Use the UIPopover method dismissPopoverAnimated: to dismiss the popover. From the docs:

Discussion

You can use this method to dismiss the popover programmatically in response to taps inside the popover window. Taps outside of the popover’s contents automatically dismiss the popover.

0
votes

How about this sample code:

- (IBAction)returnCommand:(id)sender {
     if ([viewController2 isPopoverVisible]) {
         [viewController2 dismissPopoverAnimated:YES];
         viewController2 = nil;
         return;
     }
}