SLComposeViewController - 在iOS 8中"尝试显示"错误

kev*_*kev 6 iphone objective-c ios ios8

为iOS 8更新了一些代码.我在iOS 7上运行了这个错误,这个应用程序在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];
Run Code Online (Sandbox Code Playgroud)

相当直接的东西.但是在iOS 8上我得到了以下内容

警告:尝试在PostDetailViewController上显示SLComposeViewController:0x1a238760>:0x180c5200>已经呈现(null)

我在下面看到了这个错误,我得到了它的全部内容.然而它说我的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];
    }   
}
Run Code Online (Sandbox Code Playgroud)

kev*_*kev 24

我发现在iOS 8中,ActionSheet实际上被认为是一个ViewController(至少我不知道它是不是以前),因此出现了错误信息.当我在使用的委托方法上单击按钮时,ActionSheet正在尝试被解雇:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

此委托在单击时获取按钮索引,但ActionSheet仍然可见.当发生单击时,呈现的ViewController会尝试关闭ActionSheet,然后我收到错误消息.

我切换到:

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
Run Code Online (Sandbox Code Playgroud)

(注意:didDismiss)因此,在呈现的ViewController取消ActionSheet之前,我的共享方法不会被调用,然后它可以自由地呈现共享ViewController!

希望这有助于其他人.干杯!