Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c JSON数据未按顺序保存_Objective C_Json_Uitableview - Fatal编程技术网

Objective c JSON数据未按顺序保存

Objective c JSON数据未按顺序保存,objective-c,json,uitableview,Objective C,Json,Uitableview,我返回了从大多数视图到最少视图排列的json数据,但它在表视图中的排列完全错误。。。这是它的样子 表格截图 这是返回的数组 { author = edmiester777; description = "test post #3"; id = 3; imageURL = "https://lh5.googleusercontent.com/-nmbZ4yKmKyQ/Tz6t5kpwAuI/AAAAAAAAADA/CO0s0VhvPDM/w800-h800/po

我返回了从大多数视图到最少视图排列的json数据,但它在表视图中的排列完全错误。。。这是它的样子

表格截图

这是返回的数组

 {
    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
{
规则_单元*单元;
//配置单元格。。。
if(indexPath.section==0)
{
if(indexath.row<动态行数\u最近)
{
单元格=[tableView dequeueReusableCellWithIdentifier:@“默认值”];
如果(单元格==nil)
{
cell=[[Regular_cell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“default”];
}
[cell.title_label setText:[self.recent_array_titles objectAtIndex:[indexPath行]];
[cell.views_label setText:[self.recent_array_views objectAtIndex:[indexPath行]];
[cell.author_label setText:[self.recent_array_authors objectAtIndex:[indexPath行]];
[cell setPoll_idFromString:[self.recent_array_poll_id objectAtIndex:[indexPath行]];
//图像视图的选项
cell.desc_image.contentMode=UIViewContentModeScaleSpectFill;
NSString*imageURL=[self.recent_array_poll_images objectAtIndex:[indexPath行]];
NSData*imageData=[NSData DATA WITHCONTENTSOFURL:[NSURL URLWithString:imageURL]];
[cell.desc_image setImage:[UIImage imageWithData:imageData];
}
else if(indexPath.row==动态行数\u最近行数)
{
cell=[tableView dequeueReusableCellWithIdentifier:@“查看更多信息”];
如果(单元格==nil)
{
cell=[[Regular_cell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“查看更多信息”];
}
}
其他的
{
细胞=无;
}
}
if(indexPath.section==1)
{
if(indexPath.row<动态行数\u顶部)
{
单元格=[tableView dequeueReusableCellWithIdentifier:@“默认值”];
如果(单元格==nil)
{
cell=[[Regular_cell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“default”];
}
[cell.title_label setText:[self.recent_array_titles objectAtIndex:[indexPath行]];
[cell.views_label setText:[self.recent_array_views objectAtIndex:[indexPath行]];
[cell.author_label setText:[self.recent_array_authors objectAtIndex:[indexPath行]];
[cell setPoll_idFromString:[self.recent_array_poll_id objectAtIndex:[indexPath行]];
//图像视图的选项
cell.desc_image.contentMode=UIViewContentModeScaleSpectFill;
NSString*imageURL=[self.recent_array_poll_images objectAtIndex:[indexPath行]];
NSData*imageData=[NSData DATA WITHCONTENTSOFURL:[NSURL URLWithString:imageURL]];
[cell.desc_image setImage:[UIImage imageWithData:imageData];
}
else if(indexPath.row==动态行数
{
cell=[tableView dequeueReusableCellWithIdentifier:@“查看更多信息”];
如果(单元格==nil)
{
cell=[[Regular_cell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:@“查看更多信息”];
}
}
其他的
{
细胞=无;
}
}
返回单元;
}
这就是我获取每个单独数组的方式

 -(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];
 }
-(void)addRecentCells
{
NSArray*recArray=[全局变量获取最新结果];
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*重新排列中的轮询)
{
[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”]];
动态行数=self.RECENT\u array\u titles.count;
}
[self.tableView重载数据];
}
-(无效)addTopViewedCells
{
NSArray*topArray=[全局变量获取json结果以查看顶部];
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];
对于(int i=0;i
您应该在填充NSArray后转储其输出。确保您的数据顺序正确


这也是开始使用RestKit之类的工具的好地方:

如何填充表视图的内容?我们需要查看视图控制器中的方法,例如
tableView:cellforrowatinexpath:
可能您在cellforrowatinexpath中搞砸了。添加了用于填充的代码table@EddieCallahan您可以将json响应存储在
NSMutableOrder中
 -(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];
 }