【问题标题】:Twitter integration and iOS5: semantic and parsing issuesTwitter 集成和 iOS5:语义和解析问题
【发布时间】:2011-12-01 01:44:38
【问题描述】:

我正在使用 Apple 的一些示例代码为我的应用程序编写 Twitter 集成。

但是,我收到大量错误(主要是语义和解析错误)。

如何解决?

  -(IBAction)TWButton:(id)sender {
ACAccountStore *accountstore = [[ACAccountStore alloc] init];
//Make sure to retrive twitter accounts
ACAccountType *accountType = [accountstore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountstore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
    if (granted) [{
        NSArray *accountsArray = [accountstore accountsWithAccountType:accountType];
    if ([accountsArray count] > 0) {
 ACAccount *twitterAccount = [accountsArray objectAtIndex:0];

            TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"]  parameters:[NSDictionary dictionaryWithObject:[@"Tweeted from iBrowser" forKey:@"status"] requestMethod:TWRequestMethodPOST];

            [postRequest setAccount:twitterAccount];

            [postRequest preformRequestWithHandeler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                NSString *output = [NSString stringWithFormat:@"HTTP response status: %i", [urlResponse statusCode]];
                [self preformSelectorOnMainThread:@selector(displaytext:) withObject:output waitUntilDone:NO];
            }];

        }
    }];
}
 //Now lets see if we can actually tweet

 -(void)canTweetStatus {
     if ([TWTweetComposeViewController canSendTweet]) {
         self.TWButton.enabled = YES
         self.TWButton.alpha = 1.0f;
     }else{
         self.TWButton.enabled = NO
         self.TWButton.alpha = 0.5f;
     }



}

【问题讨论】:

  • 如果使用日志中的实际文本而不是使用屏幕截图可能会更好。

标签: objective-c ios ios5 twitter


【解决方案1】:

我看到的第一个错误很容易摆脱。

Objective C 约定是将每个方法名的首字母小写。

在您的 AppDelegate.m 中使用 makeKeyAndVisible

其他错误我们可能需要查看错误在哪里(在您的代码中)被抛出,而不仅仅是什么类型的错误。

【讨论】:

  • @Micheal 谢谢,但我仍然收到错误“在'AppDelegate'类型的对象上找不到makeKeyAndVisible”,为了更好地查看错误,可以在以下位置找到它们:yfrog。 com/klvqxrp
  • 将第一个错误行更改为 if (granted) {(删除 [ 那里的括号。
  • @Micheal 谢谢 :),你对其他错误有什么建议吗?
  • 仔细查看错误,看看是拼写错误还是括号不平衡或其他类似错误。您很快就会掌握 Objective C 的窍门!
  • @Micheal,快速提问,我经常收到错误“使用未声明的标识符 postRequest”。我用我检查过的其他变量来确保我已经声明了它们。有什么想法吗?
猜你喜欢
  • 2012-09-15
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
  • 2012-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多