我在调用代码时一直收到popovercontroller错误,这是我的代码:
- (IBAction)sharePost:(id)sender {
NSArray *activityItems;
NSInteger tid = ((UIControl *) sender).tag;
if ([catName isEqualToString:@"All"])
{
//UIImage *snapshotImage = [self imageFromView:self.view];
activityItems = @[[self.titleArray objectAtIndex:tid],[self.linkArray objectAtIndex:tid],[self.imageArray objectAtIndex:tid]];
}
else
{
activityItems = @[[self.titleCatArray objectAtIndex:tid],[self.linkCatArray objectAtIndex:tid],[self.imageCatArray objectAtIndex:tid]];
}
UIActivityViewController *activityController =
[[UIActivityViewController alloc]
initWithActivityItems:activityItems
applicationActivities:nil];
[self presentViewController:activityController
animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
我想让它在iPad上工作,我已经在线查看了所有内容,但无法弄明白。
答案 0 :(得分:0)
在UIActivityViewController的文档中:
在iPad上,您必须在弹出窗口中显示视图控制器。在iPhone和iPod touch上,您必须以模态方式呈现它。
尝试:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:activityController];
[popover presentPopoverFromRect:[sender bounds]
inView:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
self.popover = popover;
} else {
[self presentViewController:activityController
animated:YES
completion:nil];
}