更新一些针对iOS 8的代码时,我在一个仅适用于iPad的应用程序中遇到了这个错误。在iOS 7中无缺陷的UIActionSheet用于显示分享选项,但使用Facebook和Twitter时却出现问题。
SLComposeViewController *facebookShare = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
//I add an image if there is one
//I set some initial text
[self presentViewController:facebookShare animated:YES completion:nil];
很简单的东西。但是在iOS 8上,我得到了下面的警告:
“警告:尝试在PostDetailViewController: 0x180c5200>上呈现SLComposeViewController: 0x1a238760>,而它已经在(null)上呈现。”
我看到了下面的错误,知道它是什么意思。但是它说我的PostDetailViewController正在呈现(null)?!?所以基本上它正在忙于什么事情?
我试图从其他VC的hearty中呈现SLComposeViewController,但我一直收到“尝试呈现错误”的消息。我尝试了从
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController和self.navigationController进行呈现,但都没有成功。我还尝试从self.navigationController推送SLComposeViewController,这实际上可以工作,但会产生不希望的结果,因为它会推送一个空白背景,然后停留在那里,直到关闭SLComposeViewController并且用户按下返回。
任何线索都将是很好的!提前感谢您。
编辑1:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)[self shareWithTwitter];
if (buttonIndex == 1)[self shareWithFacebook];
if (buttonIndex == 2)[self shareWithiMessage];
if (buttonIndex == 3)[self shareWithEmail];
if (buttonIndex == 4)[self SaveImageToCameraRoll];
}
-(void)shareWithFacebook{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
//add animal URL
SLComposeViewController *facebookShare = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookShare addURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.somelink.com/detail.aspx?id=%@",theAnimal.AnimalID]]];
//add image if there is one
if (theAnimal.PhotoUrl) {
[facebookShare addImage:imageView1.image];
}
//set initial text
if ([theAnimal.Sex isEqualToString:@"Male"]) {
[facebookShare setInitialText:[NSString stringWithFormat:NSLocalizedString(@"pop_his_fb_share", nil),theAnimal.Name]];
}else [facebookShare setInitialText:[NSString stringWithFormat:NSLocalizedString(@"pop_her_fb_share", nil),theAnimal.Name]];
[self presentViewController:facebookShare animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:NSLocalizedString(@"alert", nil)] message:[NSString stringWithFormat:NSLocalizedString(@"details_no_fb_account", nil)] delegate:nil cancelButtonTitle:[NSString stringWithFormat:NSLocalizedString(@"dismiss", nil)] otherButtonTitles:nil, nil];
[alert show];
}
}
[self shareWithFacebook];
。 - kev