解决
我的表格视图未正确刷新数据。问题是我把文本标签内容编辑部分放在“if(cell == nil)”条件中。
在
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
//This is where the mistake was
cell.textLabel.text = [[array objectAtIndex:indexPath.row] valueForKey:@"Key1"];
if ([[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue] == 1)
{ cell.detailTextLabel.text =
[NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
else { cell.detailTextLabel.text =
[NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
}
return cell;
}
在
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
}
//This is what it should have looked like in the first place
cell.textLabel.text = [[array objectAtIndex:indexPath.row] valueForKey:@"Key1"];
if ([[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue] == 1)
{ cell.detailTextLabel.text =
[NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
else { cell.detailTextLabel.text =
[NSString stringWithFormat:@"%d sometext (%d sometext), %d sometext",
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key2"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key3"] intValue],
[[[array objectAtIndex:indexPath.row] valueForKey:@"Key4"] intValue]]; }
return cell;
}