如何解决UITableView无法正确重新加载
| 解决了 我的表格视图无法正确刷新数据。问题是我将文本标签内容编辑部分放在“ 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),[[[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),[[[array objectAtIndex:indexPath.row] valueForKey:@\"Key4\"] intValue]]; }
return cell;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。