我有一个带有 CoreData 和自定义单元格的 TableView,它们都可以正常工作。
现在,当我选择一个单元格以编辑其内容并从中返回时,只需点击 UINavigationController 中的后退按钮,我就会发生一些奇怪的事情。
请看图片我的意思。似乎更新后的 UILabel 被放置在旧 UILabel 之上,而不是“更新”?我错过了什么??
您会看到顶部单元格中的差异,但它发生在所有单元格中。
编辑:添加代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
customCell = [_mainTableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (customCell == nil)
{
customCell = [[MNCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
CGRect frameTitle;
frameTitle = CGRectMake(20, 4, 195, 21);
CGRect frameSummary;
frameSummary = CGRectMake(20, 25, 250, 30);
CGRect frameDate;
frameDate = CGRectMake(200, 4, 100, 21);
MNotes *mnotes = [[self fetchedResultsController] objectAtIndexPath:indexPath];
//Strings for Title and Summary
titleString = mnotes.noteTitleString;
summaryString = mnotes.mainNoteString;
NSLog(@"TITLE STRING = %@", titleString);
//Date
SORelativeDateTransformer *relativeDateTransformer = [[SORelativeDateTransformer alloc] init];
relativeDate = [relativeDateTransformer transformedValue:mnotes.createDate];
customCell.noteTitle = [[UILabel alloc] initWithFrame:frameTitle];
customCell.noteTitle.backgroundColor = [UIColor clearColor];
customCell.noteTitle.font = [UIFont systemFontOfSize:20];
customCell.noteTitle.userInteractionEnabled = NO;
customCell.noteTitle.textColor = [self colorWithHexString:@"274D70"];
customCell.noteSummary = [[UITextView alloc] initWithFrame:frameSummary];
customCell.noteSummary.backgroundColor = [UIColor clearColor];
customCell.noteSummary.font = [UIFont systemFontOfSize:10];
customCell.noteSummary.userInteractionEnabled = NO;
customCell.noteDate = [[UILabel alloc] initWithFrame:frameDate];
customCell.noteDate.backgroundColor = [UIColor clearColor];
customCell.noteDate.font = [UIFont systemFontOfSize:16];
customCell.noteDate.userInteractionEnabled = NO;
customCell.noteDate.textColor = [self colorWithHexString:@"274D70"]; //#274D70
}
customCell.noteTitle.text = titleString;
customCell.noteSummary.text = summaryString;
customCell.noteDate.text = relativeDate;
[customCell.contentView addSubview:customCell.noteTitle];
[customCell.contentView addSubview:customCell.noteSummary];
[customCell.contentView addSubview:customCell.noteDate];
return customCell;
}