As titled, in iOS8, [UIPopoverController presentPopoverFromRect] does not work for [UIApplication sharedApplication].keyWindow any more. (It does work in iOS7)
I verified following codes:
TestViewController *test = [[TestViewController alloc] initWithNibName:nil bundle:nil];
if (testPopoverController == nil) {
testPopoverController = [[UIPopoverController alloc] initWithContentViewController:test];
testPopoverController.popoverContentSize = CGSizeMake(250, 95*5);
}
CGPoint point = [sender convertPoint:CGPointMake(0, 0) toView:nil];
CGRect rect = CGRectMake(point.x, point.y, 24, 24);
[testPopoverController presentPopoverFromRect:rect inView:[UIApplication sharedApplication].keyWindow permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
I think you have to display it in full view/viewcontroller and not in [UIApplication sharedApplication].keyWindow
So change this code:
to:
Change the inView parameter in
to
And make sure it is in dispatch block
});
Also kip changing your rect origin n size values if it is within the bounds
The best solution I've come up with is to handle it conditionally. If on iOS 7, use the working code we had for presenting a UIPopoverController on the key window. If on iOS 8, use the following:
This ends up functioning identically to:
Try the solution found at this link: http://github.com/werner77/WEPopover
1st, let's do this code:
I hope this helps. It was tested and works for iOS6-iOS8.
PS. Don't forget to check
viewDidLoad
, and give thanks to the WEPopover Library.