2012-03-14 33 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