[Assert] Assuming sourceView is not nil

当我们在适配iPad时会遇到这个报错,就是因为actionSheet当在iPad中不能显示为上弹菜单,而是有小箭头的那种形式,可以修改代码   [actionSheet show];为:

        NSString *deviceType = [UIDevice currentDevice].model;

        if([deviceType isEqualToString:@"iPhone"]) {

            [self presentViewController:actionSheet animated:YES completion:nil];

        } else if([deviceType isEqualToString:@"iPad"]){

            if ([actionSheet respondsToSelector:@selector(popoverPresentationController)]) {

                [actionSheet.popoverPresentationController setSourceView:self.view];

                [actionSheet.popoverPresentationController setSourceRect:view.frame];

            }

            [self presentViewController:actionSheet animated:YES completion:nil];

        }

view.frame为你想要该视图显示的区域

猜你喜欢

转载自blog.csdn.net/lidongxuedecsdn/article/details/80389702