1

I am using cordova with my iOS8 application. I try to load a web page in which I further navigate to selection elements like drop down which appears as a popover. When I try to switch randomly between various selection elements , the app crashes with the following error.

Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController () should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

It looks like the selection elements controller is detached and can not get back to the app control because of which it crashes.On searching ,I guess the issue because of changed behavior of UIPopoverPresentationController in iOS8 but Can anyone suggest how to fix it with cordova library in iOS8? P.S the app works fine till iOS7.

XYZ
  • 597
  • 1
  • 7
  • 19

1 Answers1

3

I fixed it using the following workaround.Nothing else seems to work. This is a reported apple bug.

-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_USEC), dispatch_get_main_queue(),
               ^{
                   [super presentViewController:viewControllerToPresent animated:flag completion:completion];
               });
}
XYZ
  • 597
  • 1
  • 7
  • 19
  • This worked wonders for me. And for anyone that doesn't know where this code should go, I simply added it within the `@implementation` of _MainViewController_, which is inside _MainViewController.m_ – munkychop Feb 04 '15 at 14:43
  • It seems to do the trick!! However the issue is still occurring randomly. It's rarely though. When I rotate the iPad orientation, sometimes the popover becomes invisible suddenly. – Rashmi Ranjan mallick May 06 '15 at 06:30