2013-08-28 45 views
5

假設您想要在用戶完成後執行某些操作。你是做什麼?爲什麼SLComposeViewController沒有委託?

它沒有委託。一旦當前視圖控制器被解僱,該怎麼辦?

+1

這就是完成處理程序是什麼。 –

+0

啊,我錯過了。現在他們使用該代替代理。 –

回答

3

在Apple文檔中,您會發現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]; 
} 

}

相關問題