Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display two json array values in single table cell in objective-c
    text
    copied!<p>I am new in objective-c and working on ios app where i am parsing json array and displaying it in table cell. I have the problem that i want to display 2 json array values in single cell but i am not getting the values properly, here is my json array</p> <pre><code> { "event_id" = 7; "fighter_id" = 26; "fighters_name" = "Kaushik Sen"; "fighters_photo" = "Kaushik.jpg"; "match_id" = 28; "match_type" = Bantamweight; "profile_link" = "link"; } { "event_id" = 7; "fighter_id" = 21; "fighters_name" = "Kultar Singh Gill"; "fighters_photo" = "Kultar.jpg"; "match_id" = 27; "match_type" = "Welterweights Main Event"; "profile_link" = "link"; } </code></pre> <p>here i want to show the fighter name from two diffrent arrays in sigle cell, eg. kaushik sen vs kultar singh gill, but i am getting alternate player names in cells. here is my objective c code.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [self MatchList]; } -(void)MatchList { NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/appleapp/eventDetails.php"]]; NSError *error; //code to execute php code NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&amp;error]; NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSMutableArray *matchListArray = [[NSMutableArray alloc]init]; matchListArray = [json objectForKey:@"products"]; arrayOfFighterName=[[NSMutableArray alloc] init]; arrOfMatchId = [[NSMutableArray alloc] init]; for( int i = 0; i&lt;[matchListArray count]; i++){ // NSLog(@"%@", [matchListArray objectAtIndex:i]); arrayOfFighterName[i]=[[matchListArray objectAtIndex:i] objectForKey:@"fighters_name"]; } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [arrayOfFighterName count]/2; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { cell = (MyFighterCell *)[tableview dequeueReusableCellWithIdentifier:kCellIdentifier]; select = indexPath.row; if(cell == nil){ cell = [[[MyFighterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease]; [cellOwner loadMyNibFile:kCellIdentifier]; cell = (MyFighterCell *)cellOwner.cell; } cell.lblPlayer1.text = [arrayOfFighterName objectAtIndex:indexPath.row]; cell.lblPlayer2.text = [arrayOfFighterName objectAtIndex:indexPath.row +1]; } </code></pre>
 

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