Search code examples
iosobjective-ciphoneuipopovercontrollerwepopover

WEPopoverController show view and after second closed it


I try to show view using popover. Since UIPopoverController does not work on IPhone i use WEPopoverController.

My code:

UIViewController *controller = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"GetDateController"];
controller.modalPresentationStyle = UIModalPresentationPopover;
WEPopoverController *pop = [[WEPopoverController alloc] initWithContentViewController:controller];
pop.delegate = self;
CGRect screen = [[UIScreen mainScreen]bounds];
CGRect r = CGRectMake(8, 8, screen.size.width-8, 57);
pop.popoverContentSize = r.size;
[pop presentPopoverFromRect:CGRectMake(200, 100, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

When I start the program, I see a pop over window, which immediately disappears. When I use UIPopoverController on IPhone program crash, on iPad everything works correctly.

What do I need to do with WEPopoverController to make it work?

Alexander.


Solution

  • That's because the view controller doesn't own the popover you create, there is no strong reference to it, and the ARC found the popover's reference count is 0, and release it immediately. All you need to do is to make the popover as the view controller's property after creation.