为什么SLComposeViewController没有委托?

5

如果用户完成某个操作后想要执行某些操作,应该怎么做?

如果没有委托,那么在一个呈现的视图控制器被解除呈现时该怎么办?


1
这就是完成处理程序的作用。 - Carl Veazey
啊,我错过了。现在他们使用那个代替委托。 - user4951
1个回答

3
在苹果文档中,你会发现SLComposeViewController具有一个完成处理程序属性,而不是代理。您只需要使用setCompletionHandler方法设置该属性即可。然后,您可以使用常量SLComposeViewControllerResult来恢复帖子是否已发布或取消,并相应地采取行动。
-(void) shareToFacebook {
//1. Set link and image
NSString *appLink = @"https://itunes.apple.com/app/id989793966";
UIImage *twitterImage = [UIImage imageNamed:@"TF_400x400.png"];

//2. Check if we can share
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    //3. Compose the share view controller
    SLComposeViewController *FBViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [FBViewController addURL:[NSURL URLWithString:appLink]];

    [FBViewController addImage:twitterImage];

    //4 Set completion handler and define actions to take
    [FBViewController setCompletionHandler:^(SLComposeViewControllerResult result)
     {
         if (result == SLComposeViewControllerResultCancelled) {

             [self addEmptyScreenButtonTargets];

         } else if (result == SLComposeViewControllerResultDone) {

             //Unlock words; show thank you screen
             [NewCardManager unlockWordsForPackage:4];

             [self openFBThankYouScreen];  
         }
     }];

    //5. Call to modally present the share controller
    [self presentViewController:FBViewController animated:YES completion:nil];
}

}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接