具体crash日志见上图,
原因 :正在使用 UIAlertController 显示您的共享按钮,而不包含 UIPopoverPresentationController 。当您的应用程序在iPad上运行时,您必须使用 UIPopoverPresentationController 。 UIPopoverPresentationController上的Apple文档。
解决方案:
- (IBAction)myButton: )sender {
UIAlertController * shareController = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * shareServiceButton = [UIAlertAction
actionWithTitle:@"Share Service"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
/ / Share something
}];
[shareController addAction:shareServiceButton];
// iPad上的用户
UIPopoverPresentationController * popoverController;
popoverController = shareController.popoverPresentationController;
popoverController.sourceView = self.view;
popoverController.sourceRect = self.myButton.frame;
popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny;
[self presentViewController:shareController animated:YES completion:nil];
}