Iphone Uitableview无法保存数据
您好,我有一个uitableview,我正在其中显示大约200行的数据。数据将显示在几个部分中,这些部分将在运行时确定。我能够获取节,但无法按正确顺序显示特定节的数据。我有数组中字典形式的数据 我的代码:Iphone Uitableview无法保存数据,iphone,Iphone,您好,我有一个uitableview,我正在其中显示大约200行的数据。数据将显示在几个部分中,这些部分将在运行时确定。我能够获取节,但无法按正确顺序显示特定节的数据。我有数组中字典形式的数据 我的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TeraGoAppDelegate *appDel = (TeraGoAppDele
- (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中删除对象,arrEqps的对象也将从arrCompEqp中删除。为什么它不保留数据。首先,如果您希望表格能够顺利工作并能够显示大量数据,您必须让单元格排队和退队 下面是对代码的一些更正:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TeraGoAppDelegate *appDel = (TeraGoAppDelegate *)[[UIApplication sharedApplication] delegate];
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier] autorelease];
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:14];
}
// Set up the cell...
cell.textLabel.text = [(NSMutableDictionary *)[appDel.arrEqp objectAtIndex:countEqpIndex] objectForKey:@"EQP_NAME"];
if(![[(NSMutableDictionary *)[appDel.arrEqp objectAtIndex:indexPath.row] objectForKey:@"select"] isEqualToString:@"0"])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
关于索引问题-我不了解确切的问题。通常每个表单元格表示数据源数组中的一个项。
什么是
countEqpIndex
?为什么不在这里也使用
indexPath.row
?我认为如果您使用Switch并选择section作为case,那么在每种情况下,您必须放置不同的数组,因此您必须为每个节划分数组,这是我的观点,我希望可以帮助您了解节,正如前面所说的,您应该为每个节设置单独的数组。它可能是一个字典数组,当顶部数组表示部分时,内部数组-单元格和字典将保存每个单元格中显示的数据(就像您现在所做的那样)。感谢michael的回复,我将继续您的建议。我做完后会告诉你的。