Disable the 'button'.
You need to disable the 'button' when the segue is triggered and re-enable it when the user's click outside the popover view.
1. Create two accessors using the usual @property & @synthesize approach.
Under @interface,
@property (strong, nonatomic) IBOutlet UIBarButtonItem *btnSettings;
@property (strong, nonatomic) UIStoryboardPopoverSegue* popSegue;
Under @implementation,
@synthesize btnSettings = _btnSettings;
@synthesize popSegue = _popSegue;
(Remember to link up the actual button to the IBOutlet in Interface Builder.)
2. Make the viewcontroller confirms to the UIPopoverControllerDelegate protocol
eg. @interface ViewController : UIViewController <UIPopoverControllerDelegate>
3. Inside the method (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
if ([segue.identifier isEqualToString:@"NAME_OF_YOUR_SEGUE"]) {
//- for this purpose alone, you don't really need a popSegue property, but having a reference
//- to the popover segue is useful
self.popSegue = (UIStoryboardPopoverSegue *)segue;
//- this gets the reference to the actual UIPopoverController which you need to set the delegate
UIPopoverController *pc = [_popSegue popoverController];
//- setting the delegate to self
//- this is important, otherwise the method under (4) won't be called and your button will remain disabled!
pc.delegate = self;
//- disable the button to prevent creating another popover
[_btnSettings setEnabled:NO];
}
4. Implement the following method in the UIPopoverControllerDelegate protocol,
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
//- renable the setting button
[_btnSettings setEnabled:YES];
}
As the name suggests, this method gets call whenever the user click outsdie the popover view.