Search code examples
iosuipopovercontrollerstoryboard

iOS - Storyboard - Delegate for pop over


I'm using storyboard in my ipad application and successfully able to do transitions, use segues etc. Currently I am showing pop over view controller on click of a button. I want to detect when the pop over dismisses. How can I do it?


Solution

  • Create a segue in view controller:

    @property (strong, nonatomic) UIStoryboardPopoverSegue* popSegue;
    

    In XIB, create an identifier called "popover" for the view.

    In Interface, write the following code:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if( [[segue identifier] isEqualToString:@"popover"] )
        {
            //[[segue destinationViewController] setDelegate:self];
            NSLog(@"%@",[[segue destinationViewController] viewControllers]);
            self.popSegue = (UIStoryboardPopoverSegue*)segue;
    .
    .
    .
    }
    

    Write the following code to dismiss the pop over by coding:

    [self.popSegue.popoverController dismissPopoverAnimated:YES];