I wanted to play with the UIPopupController, and I realized that I could not detect when my popover fired. My steps:
1. Create an example from Xcode (File → New Project → Utility Application)
2. Add to MainViewController.h UIPopoverControllerDelegate
#import "FlipsideViewController.h" @interface MainViewController : UIViewController <FlipsideViewControllerDelegate,UIPopoverControllerDelegate> @property (strong, nonatomic) UIPopoverController *flipsidePopoverController; - (IBAction)showInfo:(id)sender; @end
- (IBAction) showInfo: (id) sender
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
FlipsideViewController * controller = [[FlipsideViewController alloc] initWithNibName: @ "FlipsideViewController" bundle: nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: controller animated: YES];
} else {
if (! self.flipsidePopoverController) {
FlipsideViewController * controller = [[FlipsideViewController alloc] initWithNibName: @ "FlipsideViewController" bundle: nil];
controller.delegate = self;
self.flipsidePopoverController.delegate = self
self.flipsidePopoverController = [[UIPopoverController alloc] initWithContentViewController: controller];
}
if ([self.flipsidePopoverController isPopoverVisible]) {
[self.flipsidePopoverController dismissPopoverAnimated: YES];
} else {
[self.flipsidePopoverController presentPopoverFromBarButtonItem: sender permittedArrowDirections: UIPopoverArrowDirectionAny animated: YES];
}
}
}
- (void) popoverControllerDidDismissPopover: (UIPopoverController *) popoverController
{
NSLog (@ "OLOLO");
}
But when I click somewhere and the popover disappears, the NSLog message does not appear in the console. What am I doing wrong?
source share