Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 656
Satyam Avatar asked Nov 17 '11 16:11

Satyam


3 Answers

Here is what I did:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"popover"])
    {
        UIStoryboardPopoverSegue *pop = (UIStoryboardPopoverSegue*)segue;
        pop.popoverController.delegate = self;
    }
}
like image 100
Christopher Avatar answered Nov 12 '22 22:11

Christopher


UIPopoverController

Now with my revelation that you're talking about a UIPopoverController, here are the steps:

  1. Setup the UIPopoverController with an appropriate delegate (I'm assuming the "sender" view controller)

  2. Have your "sender" conform to the UIPopoverControllerDelegate

  3. Implement the – popoverControllerDidDismissPopover: message and have any detection logic here

  4. Implement - prepareForSegue:sender: and use the segue's destinationController to both get a reference and set the delegate, something like below:

    ((MyViewController*)segue.destinationController).delegate = self;


Modal View Controller

  1. Add a delegate to the view controller that is being presented
  2. Name your segue if you haven't already
  3. Have your base view controller implement - prepareForSegue:sender: (refer to the UIViewController documentation)
  4. Assign the sending view controller as the modal view controller's delegate in prepareForSegue:sender:
  5. Call a desired method on the delegate immediately before or after you call dismissModalViewControllerAnimated:

That is how I would approach this. I would also recommend having a formal protocol to conform your sending view controller with.

like image 7
Ryan Wersal Avatar answered Nov 12 '22 22:11

Ryan Wersal


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];        
like image 4
Satyam Avatar answered Nov 12 '22 22:11

Satyam