【发布时间】:2016-02-29 19:13:28
【问题描述】:
我遇到了大多数人在 iPad 上显示UIActivityViewController 时所面临的情况;它崩溃了:
Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7fc4f2d87d00>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.
这是我的代码:
- (void)shareLeaflet
{
NSString *forwardedString = [[NSString alloc] initWithFormat:@"Check out this leaflet\n\n %@ \n\nself.theURLToShare];
UIActivityViewController *activityViewController = nil;
if (IDIOM == IPAD)
{
NSLog(@"iPad");
activityViewController.popoverPresentationController.sourceView = self.view;
// activityViewController.popoverPresentationController.sourceRect = self.frame;
[self presentViewController:activityViewController
animated:YES
completion:nil];
}
else
{
NSLog(@"iPhone");
activityViewController = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:forwardedString, nil] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
}
在我的viewDidLoad 中,我有:
UIBarButtonItem *composeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareLeaflet)];
self.navigationItem.rightBarButtonItem = composeButton;
}
这个视图是一个UIPageViewController,它展示了一些图像,当用户点击分享按钮时,我希望 iOS 8 样式的分享表会弹出。这正是 iPhone 上发生的情况,但在 iPad 上,它继续崩溃。这让我想到了 Stack Overflow,但没有一个问题(crash on showing UIPopOverPresentationController、iOS Crash: Terminating app due to uncaught exception reason: UIPopoverPresentationController should have a non-nil sourceView、UIWebViewTerminating app due to UIPopoverPresentationController、ios8 iPad uiwebview crashes while displaying popover when user taps drop down list HTML select tag 等)对我有用。
我已经尝试了那里的所有解决方案,我完全明白了它的要求。
这就是我想要实现的目标:
【问题讨论】:
标签: ios objective-c ipad uiwebview uiactivityviewcontroller