2012-03-14 30 views
0

在我的应用程序中,我有一个操作表,其中一个按钮以模态方式打开TWTweetComposeViewController。在iPhone模拟器上,鸣叫编辑器上的取消按钮正常工作并关闭视图。但是,在iPad模拟器上,取消按钮不起作用,tweet作曲者视图仍保留在屏幕上。它甚至更加怪异,因为在按下取消按钮后,键盘缩回并且底层视图变为活动状态。它表现得好像这个观点已被解散,但它仍然存在。TWTweetComposeViewController不会在iPad模拟器上解雇

的代码我使用时,用户按下操作按钮是:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex]; 
    if ([buttonTitle isEqualToString:@"Open in Safari"]){ 
     [[UIApplication sharedApplication] openURL:[self.webView.request URL]]; 
    }else if ([buttonTitle isEqualToString:@"Twitter"]){ 
     if ([TWTweetComposeViewController canSendTweet]){ 
      TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init]; 
      [tweetSheet addURL:[self.webView.request URL]]; 
      tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){ 
       if (result == TWTweetComposeViewControllerResultCancelled){ 
        [self dismissModalViewControllerAnimated:YES]; 
       } 
      }; 
      [self presentModalViewController:tweetSheet animated:YES]; 
     }else { 
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Twitter error" message:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
      [alertView show]; 
     } 
    } 
} 

你有关于如何解决这个问题,或者是它的模拟器中的错误任何想法?

P.S .:我的应用程序是一个tabbar应用程序,此代码从标签栏的视图控制器之一调用。

+0

更新Xcode和iOS版SDK到最新版本后,它现在工作正常。 – Luiz 2012-04-25 15:12:52

回答

5

我在实际设备上遇到同样的问题。事实证明,这是苹果的SDK中的一个错误,用于TWTweetComposeViewController

查看关于OpenRadar的错误报告:http://openradar.appspot.com/radar?id=1484405

当completionHandler块被添加到 TWTweetComposeViewController,完成处理需要调用 - [UIViewController中dismissModalViewControllerAnimated:],即使为鸣叫作曲家视图驳回本身与它取消或 发送按钮。如果不这样做,触摸事件将无法到达产生推文作曲家的视图 。

只是想我要补充我是如何做的事情,即使这不是正确下列内存原则,这是一个解决办法:

[compose setCompletionHandler:^(TWTweetComposeViewControllerResult result){ 

    dispatch_async(dispatch_get_main_queue(), ^{ 

     if(self.delegate != nil) 
     { 
      if (result == TWTweetComposeViewControllerResultDone) 
      { 
       [self.delegate twitterOperation:TETwitterOperationTweet 
          completedSuccessfully:YES 
          withResponseString:@"Tweet Successful"]; 
      } 
      else if(result == TWTweetComposeViewControllerResultCancelled) 
      { 
       [self.delegate twitterOperation:TETwitterOperationTweet 
          completedSuccessfully:NO 
          withResponseString:@"Tweet Cancelled"]; 
      } 
     } 

     // Dismiss per Apple's Twitter example 
     [self.shownInViewController dismissViewControllerAnimated:YES 
                 completion:nil]; 

     // Yuck. But it's necessary. 
     [compose release]; 
    }); 
+0

将Xcode和iOS SDK更新到最新版本后,它现在工作正常。谢谢你的帮助。 – Luiz 2012-04-25 15:13:04

+0

显然,从iOS 6.1开始,这仍然是需要的。如果没有'dismissModalViewControllerAnimated:'需要第二次按取消才能关闭TWTweetComposeViewController。 – 2013-03-23 11:17:15

+0

@OrtwinGentz我已经放弃使用'TWTweetComposeViewController',因为它现在已经在iOS 6.0 +中被弃用了。相反,我使用新的社会框架:https://developer.apple.com/library/ios/#documentation/Social/Reference/Social_Framework/_index.html – Maurizio 2013-03-25 20:40:03