我使用以下代码来解析它:
-(voID)vIEwWillAppear:(BOol)animated{[super vIEwWillAppear:YES];//URL is called.if ([status isEqualToString:@"success"]){ if ([[[Json objectForKey:@"Items"] objectForKey:@"item_List"] isKindOfClass:[Nsstring class]]) { _Label.text = [Nsstring stringWithFormat:@"0"]; ItemsArray = [[NSMutableArray alloc]init]; } else { ItemsArray = [[Json objectForKey:@"Items"] objectForKey:@"item_List"]; NSLog(@"%d",[ItemsArray count]); float Amount = 0; NSLog(@"%d",[ItemsArray count]); if ([ItemsArray count]>0) { for (int i=0; i<[ItemsArray count]; i++) { NSMutableDictionary * temp3 = [ItemsArray objectAtIndex: i]; Nsstring * x = [temp3 objectForKey:@"final"]; Amount = Amount + [x floatValue]; } Label.text = [Nsstring stringWithFormat:@"%.2f",Bidamount]; } else { Label.text = [Nsstring stringWithFormat:@"0"]; } } [tableVIEwOutlet reloadData];
}
这很好用.
当字段返回字符串时我面临没问题.但是当字段是数组时,我被卡住了.
在第一次运行项目后,即使数组计数大于0,它也能正常工作.但是从第二次开始,也不会调用Cellforrowatindexpath方法….
这些是我的代码:
-(NSInteger) numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw{return 1;}-(NSInteger) tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section{NSLog(@"%d",[ItemsArray count]);return [ItemsArray count];}-(UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{static Nsstring *CellIDentifIEr = @"tableVIEwCell";UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr forIndexPath:indexPath];if (cell==nil){ cell=[[UItableVIEwCell alloc]initWithStyle:UItableVIEwCellStyleDefault reuseIDentifIEr:CellIDentifIEr];}cell.backgroundcolor = [UIcolor colorWithRed:0.0 green:0.0 blue:0.0 Alpha:0.025];NSDictionary *temp = [ItemsArray objectAtIndex:indexPath.row];UILabel *Itemname = (UILabel *)[cell vIEwWithTag:1000];Itemname.text = [temp objectForKey:@"Title"];UILabel *Cost = (UILabel *)[cell vIEwWithTag:1001];Cost.text = [temp objectForKey:@"final"];return cell;}
有人请帮帮我
解决方法 我认为问题是你没有保留你的ItemArray.NSArray* array = [[Json objectForKey:@"Items"] objectForKey:@"item_List"];ItemsArray = [NSMutableArray alloc]]initWithArray:array];
使用此代码片段.希望它可以工作.
总结以上是内存溢出为你收集整理的ios – 仅在indexpath处调用一行的单元格全部内容,希望文章能够帮你解决ios – 仅在indexpath处调用一行的单元格所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)