为iOS 8更新一些代码。我在仅限iOS的应用程序上遇到此错误。该应用程序在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上我得到了以下
警告:尝试提供SLComposeViewController:0x1a238760>上 PostDetailViewController:0x180c5200>已经呈现 (空)
我在下面看到了这个错误,我得到了它的全部内容。然而它说我的PostDetailViewController已经呈现(null)?!?所以基本上它已经没有什么忙了吗?
我试图从其他VC中提供SLComposeViewController,但我一直得到Attempt to present error
。我试过来自
UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController , and 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];
}
}
答案 0 :(得分:24)
我发现在iOS 8中ActionSheet实际上被认为是一个ViewController(至少我不知道它是不是以前),因此出现错误信息。单击我正在使用的委托方法上的按钮时,ActionSheet正在尝试被解雇:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
此委托在点击时获取按钮索引,但ActionSheet仍然可见。当发生单击时,呈现的ViewController会尝试关闭ActionSheet,然后我收到错误消息。
我切换到:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
(注意: didDismiss )因此,在呈现的ViewController取消ActionSheet之前,我的共享方法不会被调用,然后它可以自由呈现共享ViewController!
希望这有助于其他人。干杯!
答案 1 :(得分:-1)
试试下面的事情。
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:fbViewController animated:YES completion:nil];
}];