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?
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;
}
}
Now with my revelation that you're talking about a UIPopoverController
, here are the steps:
Setup the UIPopoverController
with an appropriate delegate (I'm assuming the "sender" view controller)
Have your "sender" conform to the UIPopoverControllerDelegate
Implement the – popoverControllerDidDismissPopover:
message and have any detection logic here
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;
- prepareForSegue:sender:
(refer to the UIViewController documentation
)prepareForSegue:sender:
dismissModalViewControllerAnimated:
That is how I would approach this. I would also recommend having a formal protocol to conform your sending view controller with.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With