2013-11-10 22 views
0

我正在使用AFNetworking 1.2來創建一個應用程序,顯示來自用戶的推文。該應用程序已成功驗證用戶身份,但不顯示推文。這是我正在做什麼來接收推文。問題加載推文到UITableView W/AFNetworking 1.2推文

- (void)fetchTweets 
{ 
    self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"4oFCF0AjP4PQDUaCh5RQ" secret:@"NxAihESVsdUXSUxtHrml2VBHA0xKofYKmmGS01KaSs"]; 

    [self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"/oauth/request_token" userAuthorizationPath:@"/oauth/authorize" callbackURL:[NSURL URLWithString:@"floadt://success"] accessTokenPath:@"/oauth/access_token" accessMethod:@"POST" scope:nil success:^(AFOAuth1Token *accessToken, id responseObject) { 
     [self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; 
     [self.twitterClient getPath:@"statuses/user_timeline.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { 
      NSArray *responseArray = (NSArray *)responseObject; 
      tweets = responseArray; 
      [responseArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
       NSLog(@"Success: %@", obj); 
      }]; 
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      NSLog(@"Error: %@", error); 
     }]; 
    } failure:^(NSError *error) { 
     NSLog(@"Error: %@", error); 
    }]; 
} 

這裏是我在嘗試接收的推文裝入到的UITableView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"TweetCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    NSDictionary *tweet = [tweets objectAtIndex:indexPath.row]; 
    NSString *text = [tweet objectForKey:@"text"]; 
    NSString *name = [[tweet objectForKey:@"user"] objectForKey:@"name"]; 

    cell.textLabel.text = text; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name]; 

    return cell; 
} 

我已經加入小區標識符在故事板了,所以這不是問題。獲取所有的鳴叫並將其分配給數組

回答

0
[tableView reloadData]; 

刷新表意味着

- (void)fetchTweets 
{ 
    self.twitterClient = [[AFOAuth1Client alloc] initWithBaseURL:[NSURL URLWithString:@"https://api.twitter.com/1.1/"] key:@"4oFCF0AjP4PQDUaCh5RQ" secret:@"NxAihESVsdUXSUxtHrml2VBHA0xKofYKmmGS01KaSs"]; 

    [self.twitterClient authorizeUsingOAuthWithRequestTokenPath:@"/oauth/request_token" userAuthorizationPath:@"/oauth/authorize" callbackURL:[NSURL URLWithString:@"floadt://success"] accessTokenPath:@"/oauth/access_token" accessMethod:@"POST" scope:nil success:^(AFOAuth1Token *accessToken, id responseObject) { 
     [self.twitterClient registerHTTPOperationClass:[AFJSONRequestOperation class]]; 
     [self.twitterClient getPath:@"statuses/user_timeline.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { 
      NSArray *responseArray = (NSArray *)responseObject; 
      tweets = responseArray; 
      [tableView reloadData]; 
      //^ Add this line 
      [responseArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
       NSLog(@"Success: %@", obj); 
      }]; 
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
      NSLog(@"Error: %@", error); 
     }]; 
    } failure:^(NSError *error) { 
     NSLog(@"Error: %@", error); 
    }]; 
} 

注:tableView是你的tableview名

+0

我的tableview實際上是所謂的TableView,它是outleted在我的文件的.h部分是否會改變它。 – Prad

+0

我改變了我的表的名字到tableView,它仍然沒有改變 – Prad