嗨,我有一个uitableview,我显示了一些约200行的数据。数据将以几个部分显示,这些部分将在运行时确定。我能够得到部分,但我无法以正确的顺序显示特定部分的数据。我有一个数组字典形式的数据。Uitableview无法保存数据
我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TeraGoAppDelegate *appDel = (TeraGoAppDelegate *)[[UIApplication sharedApplication] delegate];
UITableViewCell *cell = nil;
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = [(NSMutableDictionary *)[appDel.arrEqp objectAtIndex:countEqpIndex] objectForKey:@"EQP_NAME"];
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:14];
if(![[(NSMutableDictionary *)[appDel.arrEqp objectAtIndex:indexPath.row] objectForKey:@"select"] isEqualToString:@"0"])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Set up the cell...
return cell;
}
我想在每一个部分使用indexPath.row但其值初始化为0我无法从阵列中的数据在这种情况下我没有获取数据的数组索引。我将如何获得我需要显示的值的数组的索引?
更新:
[dictComp setObject:arrEqps forKey:CompName];
[arrCompEqp addObject:dictComp];
[arrEqps removeAllObjects];
我使用上面的代码在表视图阵列添加数据,但一旦我从arrEqps删除对象,从arrCompEqp arrEqps的对象也被去除。为什么它不保留数据。
关于正如已经说过的那样,每个部分应该有一个单独的数组。它可能是一组字典数组,当顶部数组代表段时,内部数组 - 单元格和字典将保存要在每个单元格中显示的数据(就像您现在这样做)。 – 2010-06-07 10:32:41
感谢迈克尔您的回复,我会继续提出您的建议。当我完成它时,我会让你知道。 – pankaj 2010-06-08 05:52:00