UIPopoverController not presenting in iPad iOS 8

社会主义新天地 提交于 2019-12-19 06:28:49

问题


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..


回答1:


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];
    });
}



回答2:


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...



来源:https://stackoverflow.com/questions/25805643/uipopovercontroller-not-presenting-in-ipad-ios-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!