Reputation: 9189
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.
Upvotes: 1
Views: 648
Reputation: 1
How about this sample code:
- (IBAction)returnCommand:(id)sender {
if ([viewController2 isPopoverVisible]) {
[viewController2 dismissPopoverAnimated:YES];
viewController2 = nil;
return;
}
}
Upvotes: 0
Reputation: 131503
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.
Upvotes: 1