SLComposeViewController取消其父VC

时间:2013-11-22 12:08:49

标签: iphone objective-c uiviewcontroller ios7 slcomposeviewcontroller

我正在使用SLComposeViewController在Twitter上发布,一切正常,但是当帖子成功时 也解散父视图控制器。

-(void)showTweetSheet
{
//  Create an instance of the Tweet Sheet
    SLComposeViewController *tweetSheet = [SLComposeViewController
                                     composeViewControllerForServiceType:
                                     SLServiceTypeTwitter];

   // Sets the completion handler.  Note that we don't know which thread the
   // block will be called on, so we need to ensure that any UI updates occur
   //  on the main queue
   tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
    switch(result) {
    //  This means the user cancelled without sending the Tweet
      case SLComposeViewControllerResultCancelled:
    NSLog(@"User Canceled the Twitter Sharing");
      break;
    //  This means the user hit 'Send'
      case SLComposeViewControllerResultDone:
    NSLog(@"Tweet has been posted successfully!");
      break;
   }

   //  dismiss the Tweet Sheet
   dispatch_async(dispatch_get_main_queue(), ^{
     [self dismissViewControllerAnimated:NO completion:^{
     NSLog(@"Tweet Sheet has been dismissed.");
   }];
  });
 };

 //  Set the initial body of the Tweet
 [tweetSheet setInitialText:[NSString stringWithFormat:@"Hurrah! I have earned %@ Badge on %@ app.",    [badges objectAtIndex:badgeID], [UIApplication appDisplayName]]];

  //  Adds an image to the Tweet.  For demo purposes
 if (![tweetSheet addImage:[UIImage imageNamed:[NSString stringWithFormat:@"Badge%d.jpg", badgeID]]]) {
   NSLog(@"Unable to add the image!");
 }

 //  Add an URL to the Tweet.  You can add multiple URLs.
 if (![tweetSheet addURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com//app//id%@", [UserDefaultsOperations getAppleAppID]]]]){
  NSLog(@"Unable to add the URL!");
 }

 //  Presents the Tweet Sheet to the user
  [self presentViewController:tweetSheet animated:NO completion:^{
   NSLog(@"Tweet sheet has been presented.");
 }];

}

我不想解雇父视图控制器。请帮忙!

1 个答案:

答案 0 :(得分:0)

只需在上面的代码中注释这些行:

//  dismiss the Tweet Sheet
dispatch_async(dispatch_get_main_queue(), ^{
     [self dismissViewControllerAnimated:NO completion:^{
     NSLog(@"Tweet Sheet has been dismissed.");
}];