IPad: how to close a UIPopoverController from a pop-up ViewController

I convert and iphone project to ipad. On iphone, I have mainViewController which opens loginViewController with addSubView.

On an iPad, I would like to display this 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];

It works great. The problem is that loginViewController is ending its "business". On the iPhone, I just call simple [self.view removeFromSuperview];But on the ipad, this removes the view from the PopoverController, but the frame of the popup remains.

So my question is: is there any easy way from loginViewController to remove my PopoverController container (without using a delegate or notifications)?

+5
source share
2 answers

Yes, yours loginViewControllershould contain a link to popover. You can then use dismissPopoverAnimated:your popover method to remove it.

+9
source

Actually, I want to implement this, but I remembered that we can access the application delegate, which, in turn, will have access to the main view of this file. There you can save the popover property, and you can call dismissPopoverAnimated.

Like this:

MyAppDelegate *app = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
MyViewController * myView =[app viewController];
[myView.popover dismissPopoverAnimated:YES];
+1
source

All Articles