ios控制器怎么推出popoverpresentationcontroller
1个回答
展开全部
iPad中使用presentViewController如果不设置popoverPresentationController会崩溃,iPhone貌似是不会的
1、在iOS 8.02 一定要设定popoverPresentationController 不然程式会Crash
UIActivityViewController *avc = ....;
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
//如果是UIButton
UIButton *btn = (UIButton *)sender;
avc.popoverPresentationController.sourceView = btn;
avc.popoverPresentationController.sourceRect = btn.bounds;
//如果是BarItem
avc.popoverPresentationController. barButtonItem = sender;
}
[self presentViewController:avc animated:YES completion:nil];
2、UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
解决办法是 在 presentController 前面加一句 if ([activityViewController respondsToSelector:@selector(popoverPresentationController)]) {
activityViewController.popoverPresentationController.sourceView = self.view;
}
1、在iOS 8.02 一定要设定popoverPresentationController 不然程式会Crash
UIActivityViewController *avc = ....;
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) {
//如果是UIButton
UIButton *btn = (UIButton *)sender;
avc.popoverPresentationController.sourceView = btn;
avc.popoverPresentationController.sourceRect = btn.bounds;
//如果是BarItem
avc.popoverPresentationController. barButtonItem = sender;
}
[self presentViewController:avc animated:YES completion:nil];
2、UIActivityViewController *activityController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
解决办法是 在 presentController 前面加一句 if ([activityViewController respondsToSelector:@selector(popoverPresentationController)]) {
activityViewController.popoverPresentationController.sourceView = self.view;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询