嗨,我有一個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