iPad: how to close UIPopoverController from within the "popped" ViewController
Asked Answered
I

2

5

I'm converting and iphone project to ipad. On iphone I have a mainViewController that opens a loginViewController using addSubView.

On the iPad I would like to display that loginViewController in a popover. so I did something like:

UIPopoverController *loginPop = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
[loginPop presentPopoverFromRect:CGRectMake(150, 150, 90, 90) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:true];

This works fine. The problem is when the loginViewController finishes its "business". On the iPhone I just call a simple [self.view removeFromSuperview]; But on the ipad this causes the view to be removed from the PopoverController but the frame of the popup stays.

So my question is: is there any simple way from within the loginViewController to remove its PopoverController container (without using delegate or notifications)?

Infiltration answered 24/3, 2011 at 9:48 Comment(0)
D
9

Yes, your loginViewController should keep a reference to the popover. Then you can use the dismissPopoverAnimated: method of your popover itself to remove it.

Deboradeborah answered 24/3, 2011 at 12:38 Comment(2)
Wouldent that give a circular reference? Since the PopoverController is initialized with the loginController (and obviously has a reference to this)? Seems like an anti-pattens here... Anyone?Hildegard
You'd probably make this reference weak.Seedbed
V
1

Actually, I want to implement that, but I remembered that we can access application delegate, which in turn will have access to main view of it, In there, you can store property of the popover, and you can call the dismissPopoverAnimated.

Like this :

MyAppDelegate *app = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
MyViewController * myView =[app viewController];
[myView.popover dismissPopoverAnimated:YES];
Ventura answered 19/5, 2011 at 3:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.