Search code examples
objective-cdelegatesuipopovercontroller

write a function that invokes as a result of setting setDelegate:self


I understand how to create my own delegate, but don't know how to write a method for the following situation

I'm setting a popover

NotesViewController *viewControllerForPopover =(NotesViewController*)
[self.storyboard instantiateViewControllerWithIdentifier:@"NotesPopover"];


popover = [[UIPopoverController alloc]
           initWithContentViewController:viewControllerForPopover];
[popover setPopoverContentSize:viewControllerForPopover.size];
[popover setDelegate:self];
[popover presentPopoverFromBarButtonItem: p_barButton permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

in this line [popover setDelegate:self]; I make sure that when the popover disappears it will "return" to the current viewController, but how can I set a function to be invoked with that delegate?


Solution

  • found the solution: in the UIViewController interface make sure you have the protocol <UIPopoverControllerDelegate> if not add it

    then in the implementation file write this function

    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    {
        //do the stuff needed after the popover was closed
    }