Reputation: 15894
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?
Upvotes: 8
Views: 10749
Reputation: 553
An Objective-C code for the question is below.
if ([segue.identifier isEqualToString:@"home_login"])
{
UIViewController *dest = segue.destinationViewController;
dest.popoverPresentationController.delegate = self;
}
- (BOOL) popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController
{
return NO;
}
Upvotes: 0
Reputation: 1264
Since UIStoryboardPopoverSegue
is deprecated in iOS 9, you can use a UIStoryboardPopoverPresentationSegue
.
Then in prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
you can set the delegate like this:
if let identifier = segue.identifier where identifier == "showPopover" {
let destVC = segue.destinationViewController as! UIViewController
destVC.popoverPresentationController?.delegate = self
}
Upvotes: 1
Reputation: 6046
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;
}
}
Upvotes: 14
Reputation: 15894
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];
Upvotes: 4
Reputation: 3228
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.
Upvotes: 7