Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd arrays into Cell Row from Twitter Client feeds in iphone
    text
    copied!<p>I am new to parsing jSON file in objective C and I want to parse Twitter json feeds users names from the list. I am trying to get the list of followers of a user and parse them to get the user_ids and then again call another URL to get their names and profile pics. I am getting the names of the persons but I am not able to parse the list correctly. If anybody can help me out here, it will be really helpful. My code for fetching the data :</p> <pre><code>-(void) fetchData{ ACAccountStore *account = [[ACAccountStore alloc] init]; ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error){ if (granted == YES) { NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType]; if ([arrayOfAccounts count] &gt; 0) { ACAccount *acct = [arrayOfAccounts objectAtIndex:0]; NSString *username = acct.username; NSLog(@"Account : %@", username); TWRequest *fetchFriendsFollowers = [[TWRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1/followers/ids.json?screen_name=%@",acct.username]] parameters:nil requestMethod:TWRequestMethodGET]; [fetchFriendsFollowers performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error){ if ([urlResponse statusCode] == 200 ) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *jsonParsingError = nil; NSDictionary *response = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;jsonParsingError]; self.responseArray = [response objectForKey:@"ids"]; for (int i =0 ; i &lt; [self.responseArray count]; i++) { NSString *user_id = [self.responseArray objectAtIndex:i]; TWRequest *fetchFriendsFollowersNames = [[TWRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1/users/lookup.json?user_id=%@",user_id]] parameters:nil requestMethod:TWRequestMethodPOST]; [fetchFriendsFollowersNames performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error){ if ([urlResponse statusCode] == 200 ) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *jsonParsingError = nil; NSArray *response = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&amp;jsonParsingError]; for (NSDictionary *user in response) { [self.userNameArray addObject:[user objectForKey:@"name"]]; [self.tableView reloadData]; } }); } }]; } NSLog(@"responseArray %@ for user: %@",self.responseArray,username); }); } }]; } else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please add twitter accounts on your phone and log back in." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [alert show]; } } }]; </code></pre> <p>}</p> <p>And then I am displaying it in cellForRowAtIndexPath the list of all the user names. It actually gets the list and repeats the name in all the cells. I know I am doing something silly mistake but cannot figure out since i have been looking at this for a while and cant get it fix.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } for (int i=0; i &lt; [self.userNameArray count]; i++) { NSLog(@"Text : %@", [self.userNameArray objectAtIndex:i]); cell.textLabel.text = [self.userNameArray objectAtIndex:i]; } return cell; </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload