2013-07-03 3 views
0

Я вернулся JSon данные, которые расположены в большинстве взглядов наименее взглядов, но она устроена совершенно неправильно в табличном ... вот что это выглядит какJSON данные не хранятся в порядке

скриншот таблицы

enter image description here

здесь возвращаемый массив

{ 
    author = edmiester777; 
    description = "test post #3"; 
    id = 3; 
    imageURL = "https://lh5.googleusercontent.com/-nmbZ4yKmKyQ/Tz6t5kpwAuI/AAAAAAAAADA/CO0s0VhvPDM/w800-h800/potion.jpg"; 
    pubDate = "2013-07-01 12:49:01"; 
    title = "Post #3"; 
    views = 64774; 
}, 
    { 
    author = edmiester777; 
    description = "@*$(DS(XC#*$&@(())));"; 
    id = 1; 
    imageURL = "http://0.tqn.com/d/sbinformation/1/0/D/A/twitter_newbird_boxed_whiteonblue.png"; 
    pubDate = "2013-07-01 12:21:01"; 
    title = "First Post Ever!"; 
    views = 1035; 
}, 
    { 
    author = edmiester777; 
    description = "this post is testing the UIImage loading capability of the custom table view"; 
    id = 2; 
    imageURL = "http://greatergood.berkeley.edu/images/uploads/Thnx4-logo-small.png"; 
    pubDate = "2013-07-01 12:46:28"; 
    title = "Second Post Ever!"; 
    views = 645; 
} 

что может идти неправильно при отображении данных?

код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
Regular_Cell *cell; 
// Configure the cell... 
if(indexPath.section == 0) 
{ 
    if(indexPath.row < NUMBER_OF_DYNAMIC_ROWS_RECENT) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"default"]; 
     if(cell == nil) 
     { 
      cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default"]; 
     } 
     [cell.title_label setText:[self.recent_array_titles objectAtIndex:[indexPath row]]]; 
     [cell.views_label setText:[self.recent_array_views objectAtIndex:[indexPath row]]]; 
     [cell.author_label setText:[self.recent_array_authors objectAtIndex:[indexPath row]]]; 
     [cell setPoll_idFromString:[self.recent_array_poll_id objectAtIndex:[indexPath row]]]; 

     //options for image view 
     cell.desc_image.contentMode = UIViewContentModeScaleAspectFill; 
     NSString *imageURL = [self.recent_array_poll_images objectAtIndex:[indexPath row]]; 
     NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]; 
     [cell.desc_image setImage:[UIImage imageWithData:imageData]]; 
    } 
    else if(indexPath.row == NUMBER_OF_DYNAMIC_ROWS_RECENT) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"See More"]; 
     if(cell == nil) 
     { 
      cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"See More"]; 
     } 
    } 
    else 
    { 
     cell = nil; 
    } 
} 
if(indexPath.section == 1) 
{ 
    if(indexPath.row < NUMBER_OF_DYNAMIC_ROWS_TOP) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"default"]; 
     if(cell == nil) 
     { 
      cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default"]; 
     } 
     [cell.title_label setText:[self.recent_array_titles objectAtIndex:[indexPath row]]]; 
     [cell.views_label setText:[self.recent_array_views objectAtIndex:[indexPath row]]]; 
     [cell.author_label setText:[self.recent_array_authors objectAtIndex:[indexPath row]]]; 
     [cell setPoll_idFromString:[self.recent_array_poll_id objectAtIndex:[indexPath row]]]; 

     //options for image view 
     cell.desc_image.contentMode = UIViewContentModeScaleAspectFill; 
     NSString *imageURL = [self.recent_array_poll_images objectAtIndex:[indexPath row]]; 
     NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]; 
     [cell.desc_image setImage:[UIImage imageWithData:imageData]]; 
    } 
    else if(indexPath.row == NUMBER_OF_DYNAMIC_ROWS_TOP) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"See More"]; 
     if(cell == nil) 
     { 
      cell = [[Regular_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"See More"]; 
     } 
    } 
    else 
    { 
     cell = nil; 
    } 
} 

return cell; 
} 

это, как я получаю каждый отдельный массиву

-(void)addRecentCells 
{ 
NSArray *recArray = [Global_Vars get_json_results_for_recent]; 
self.recent_array_titles  = [[NSMutableArray alloc]init]; 
self.recent_array_authors  = [[NSMutableArray alloc]init]; 
self.recent_array_views  = [[NSMutableArray alloc]init]; 
self.recent_array_poll_id  = [[NSMutableArray alloc]init]; 
self.recent_array_poll_images = [[NSMutableArray alloc]init]; 
for(NSDictionary *poll in recArray) 
{ 
    [self.recent_array_titles  addObject:poll[@"title"]]; 
    [self.recent_array_authors  addObject:[NSString stringWithFormat:@"Author: %@",poll[@"author"]]]; 
    [self.recent_array_views  addObject:[NSString stringWithFormat:@"Views : %@",poll[@"views"]]]; 
    [self.recent_array_poll_id  addObject:[NSString stringWithFormat:@"%@",poll[@"id"]]]; 
    [self.recent_array_poll_images addObject:[NSString stringWithFormat:@"%@",poll[@"imageURL"]]]; 
    NUMBER_OF_DYNAMIC_ROWS_RECENT = self.recent_array_titles.count; 
} 
[self.tableView reloadData]; 
} 
-(void)addTopViewedCells 
{ 
NSArray *topArray = [Global_Vars get_json_results_for_top_viewed]; 
self.top_views_array_titles  = [[NSMutableArray alloc]init]; 
self.top_views_array_authors  = [[NSMutableArray alloc]init]; 
self.top_views_array_views  = [[NSMutableArray alloc]init]; 
self.top_views_array_poll_id  = [[NSMutableArray alloc]init]; 
self.top_views_array_poll_images = [[NSMutableArray alloc]init]; 
for(int i = 0; i < topArray.count; i++) 
{ 
    NSDictionary *poll = [topArray objectAtIndex:i]; 
    [self.top_views_array_titles  addObject:poll[@"title"]]; 
    [self.top_views_array_authors  addObject:[NSString stringWithFormat:@"Author: %@",poll[@"author"]]]; 
    [self.top_views_array_views  addObject:[NSString stringWithFormat:@"Views : %@",poll[@"views"]]]; 
    [self.top_views_array_poll_id  addObject:[NSString stringWithFormat:@"%@",poll[@"id"]]]; 
    [self.top_views_array_poll_images addObject:[NSString stringWithFormat:@"%@",poll[@"imageURL"]]]; 
    NUMBER_OF_DYNAMIC_ROWS_TOP = self.top_views_array_titles.count; 
} 
[self.tableView reloadData]; 
} 
+1

Как вы заселить содержимое табличных? Нам нужно будет увидеть методы в вашем контроллере вида, такие как 'tableView: cellForRowAtIndexPath:' –

+1

Предположительно, вы делаете ошибки в cellForRowAtIndexPath. –

+0

добавленный код для заполнения таблицы –

ответ

0

Вы должны сбросить вывод ваших NSArrays после заполнения их. Убедитесь, что ваши данные упорядочены правильно.

Это также отличное место, чтобы начать использовать что-то вроде RestKit: http://github.com/RestKit/RestKit

Смежные вопросы