UIPopoverController not presenting in iPad iOS 8

2019-02-16 23:52发布

I am using UIPopoverController in iOS 8 iPad for imagepicker.Its working in iOS 7 but not in iOS 8.The popover is not displayed and popoverControllerDidDismissPopover is called immediately.Please suggest a solution.. Here the code am using:

UIPopoverController *popVC= [[UIPopoverController alloc] initWithContentViewController:pickerController];
_pop = popVC;
_pop.delegate = self;
[_pop presentPopoverFromRect:attachBtnFrame inView:_sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];

Thanks..

2条回答
仙女界的扛把子
2楼-- · 2019-02-17 00:22

Finally found the solution: Present the Popover in main thread as below.

if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0)
{
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      [_pop presentPopoverFromRect:attachBtnFrame inView:_sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
    });
}
查看更多
家丑人穷心不美
3楼-- · 2019-02-17 00:38

Put this Method in your appDelegate.m

+(BOOL)isIOS8

{
     NSString* version=[[UIDevice currentDevice] systemVersion];
    if ([version integerValue]>=8.0)
     {
         return YES;
     }
     else
     {
         return NO;
     } 
}

now, when you want to use PopoverController just Check system OS by above method like

if([AppDelegate isIOS8])

than use this Method

if([AppDelegate isIOS8])
        {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(),
                 ^{[self.popover presentPopoverFromRect:popoverRect
                                              inView:self.view
                            permittedArrowDirections:UIPopoverArrowDirectionUp
                                            animated:YES];});
        }
        else
        {
            [self.popover presentPopoverFromRect:popoverRect
                                          inView:self.view
                        permittedArrowDirections:UIPopoverArrowDirectionAny
                                        animated:YES ];
        }

this Method works for me very well and it should work for you...

查看更多
登录 后发表回答