我想在用户点击分享按钮时显示popoverPresentationController。我用动作表分享按钮。 这是我的代码,它不适用于iPad:
NSString *aText = @"Some Text";
NSURL *aUrl = [NSURL URLWithString:@"www.demo.com"];
NSArray *objectsToShare = @[aText,aUrl];
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = @[
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeAirDrop,
UIActivityTypeAddToReadingList,
UIActivityTypeCopyToPasteboard,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePrint,
UIActivityTypePostToFlickr,
UIActivityTypePostToTencentWeibo,];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityViewController animated:YES completion:nil];
}
else {
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4 + 20, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
iPad上的错误(屏幕上没有显示)。那我怎么解决呢?
答案 0 :(得分:2)
是的,我得到了它并解决了我的问题。
在iPad上,活动视图控制器将使用popoverPresentationController显示为弹出框,并使用UIAlertController进行节目弹出。
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Share" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *aText = @"Some Text";
NSURL *aUrl = [NSURL URLWithString:@"www.demo.com"];
NSArray *objectsToShare = @[aText,aUrl];
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = @[
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeAirDrop,
UIActivityTypeAddToReadingList,
UIActivityTypeCopyToPasteboard,
UIActivityTypeSaveToCameraRoll,
UIActivityTypePrint,
UIActivityTypePostToFlickr,
UIActivityTypePostToTencentWeibo,];
UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityViewController];
[popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4 , 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}]];
actionSheet.popoverPresentationController.sourceView = self.view;
actionSheet.popoverPresentationController.sourceRect = CGRectMake(self.view.frame.size.width, btn.frame.origin.y +btn.frame.size.height , 0, 0);
actionSheet.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:actionSheet animated:YES completion:nil];