2011-12-29 59 views
1

**我添加了Twitter.framework和Accounts.framework。iOS 5.0中的Twitter集成

並導入了Twitter.h頭文件。

但我得到**錯誤「未聲明的標識符‘tweetSheet’的使用」

Class TWTweetComposeViewController = NSClassFromString(@"TWTweetComposeViewController"); 
if(TWTweetComposeViewController != nil) { 



    //For iOS 5.0 onwards 
    if ([TWTweetComposeViewController canSendTweet]) { 
     //Create the tweet sheet 
     TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init]; 

     //Customize the tweet sheet here 
     //Add a tweet message 
     [tweetSheet setInitialText:[[self getShareContent] objectForKey:@"twitterContent"]]; 

     //Set a blocking handler for the tweet sheet 
     tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result){ 
      if (TWTweetComposeViewControllerResultDone) { 
           UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Tweeted" 
                        message:@"You successfully tweeted" 
                        delegate:self cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil]; 
           [alertView show]; 
           [alertView release]; 
      } else if (TWTweetComposeViewControllerResultCancelled) { 
           UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Ooops..." 
                        message:@"Something went wrong, try again later" 
                        delegate:self 
                      cancelButtonTitle:@"OK" 
                      otherButtonTitles:nil]; 
           [alertView show]; 
           [alertView release]; 
      } 

      [self dismissModalViewControllerAnimated:YES]; 
     }; 

     //Show the tweet sheet! 
     [self presentModalViewController:tweetSheet animated:YES]; 

    } else { 

      UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil 
                   message:@"You need to configure your Twitter account in the Settings" 
                   delegate:self cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil]; 
      [alertView show]; 
      [alertView release]; 


    } 

} 
+0

[這裏](http://dummycode.com/b/3)是一篇關於將Twitter API與iOS集成的好帖子。 – 2013-07-15 22:39:48

回答

1

,因爲你已經創建具有相同的名稱作爲類變量(TWTweetComposeViewController)編譯器是迷茫名稱。更改第一個2線:

Class tweetComposeViewController = NSClassFromString(@"TWTweetComposeViewController"); 
if(tweetComposeViewController != nil) { 

...你應該都不錯。