【发布时间】:2014-03-26 14:37:19
【问题描述】:
您好,我正在使用返回 JSON 文档的 Web 服务。在该文档中有几个对象,每个对象都包含一个“STATE”值(其中包括“ADDRESS”、“DISTANCE”等)。此“STATE”值可以是“ARCHIVED”或“ACTIVE”。我想要做的是将具有“STATE”的“ARCHIVED”值的对象加载到archivedProcessTV中,将其他对象加载到activeProcessTV中。
我设法用所需数据填充了两个可变数组,但是当 TableView 重新加载时,它们会将所有对象重新加载到单元格中。
这是我在 connectionDidFinishLoading 上所做的事情:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
NSLog(@"Entrou no connectionDidFinishLoading");
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
process = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil] objectForKey:@"GetGesturbeDataJsonResult"];
NSInteger i = 0;
archived = [[NSMutableArray alloc] init];
active = [[NSMutableArray alloc] init];
for (NSObject *array1 in process) {
while (i <= process.count) {
if([[[process objectAtIndex:i] objectForKey:@"STATE" ] isEqualToString:@"ARCHIVED"])
{
[archived addObject:[process objectAtIndex:i]];
i++;
}else
[active addObject:[process objectAtIndex:i]];
i++;
}
}
[activeProcessTV reloadData];
[archivedProcessTV reloadData];
}
感谢您的帮助!
编辑:
-(UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:@"a cell"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"a cell"];
cell.textLabel.text = [[process objectAtIndex:indexPath.row] objectForKey:@"DISTANCE"];
return cell;
}
【问题讨论】:
-
显示你的表格视图数据源方法实现
-
@Wain 我不知道你的意思是不是我刚刚添加到问题中的内容。 (抱歉无知)
-
您是否在某处合并这两个数组(活动和存档)并将所有值混合在一起?
-
@Justafinger 不,我不这么认为
标签: ios objective-c json web-services uitableview