我有一个 tableView 和一个 detailView ,用户可以在其中更改数据。在我以编程方式将单元格从字幕更改为自定义之前,它工作得很好。现在,当我编辑数据并返回时,我看到新数据与旧数据重叠,尽管 viewDidLoad 中有 [self.tableView reloadData]。数据更改运行良好,因为如果我重新启动应用程序,则会显示新数据.
此外,单元格之间的分隔线也没有覆盖整个宽度。
只是为了确保这里是自定义单元格的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UILabel *mainLabel, *detailLabel, *secondLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.0, 220.0, 15.0)];
// mainLabel.tag = MAINLABEL_TAG;
mainLabel.font = [UIFont systemFontOfSize:14.0];
mainLabel.textAlignment = NSTextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];
secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 5.0, 200, 15.0)];
// secondLabel.tag = MAINLABEL_TAG;
secondLabel.font = [UIFont systemFontOfSize:10.0];
secondLabel.textAlignment = NSTextAlignmentRight;
secondLabel.textColor = [UIColor whiteColor];
secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:secondLabel];
detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 20.0, 220.0, 25.0)];
// detailLabel.tag = SECONDLABEL_TAG;
detailLabel.font = [UIFont systemFontOfSize:12.0];
detailLabel.textAlignment = NSTextAlignmentLeft;
detailLabel.textColor = [UIColor lightGrayColor];
detailLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:detailLabel];
SNMGps *aCell = [arrayOfCell objectAtIndex:indexPath.row];
mainLabel.text = [NSString stringWithFormat:@"%@", aCell.name];
secondLabel.text = [NSString stringWithFormat:@"%d",aCell.gpsID];
detailLabel.text = [NSString stringWithFormat:@"%@",aCell.notes];
return cell;
}
谢谢。