我发现了一些与我的问题相似但不完全相同的帖子。
在我的应用程序中,用户可以在几个 uitableviews 之间导航以深入了解所需的结果。当用户向前,然后向后,然后向前等时,很明显,行正在重新绘制/重写,并且文本变得越来越粗。
我发现在某些帖子中,这可能与我在方法中使用 uilable 创建行的cellforrowatindexpath
方式有关。
有什么我需要做的,以便每次用户在表格视图之间前进和后退时不会重新填充/重绘行吗?我是否需要在下面的代码中添加一些内容或向 viewwillappear 方法添加一些内容(当前 viewwillappear 中有一个“reloaddata”,但似乎没有帮助)?
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel *label = [[[UILabel alloc] init] autorelease];
label.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
label.frame = CGRectMake(10.0f, 10.0f, 220.0f, 22.0f);
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
label.text = [mapareaArray objectAtIndex:indexPath.row];
[cell.contentView addSubview:label];
CustomCellBackgroundView *bgView = [[CustomCellBackgroundView alloc] initWithFrame:CGRectZero];
bgView.borderColor = [UIColor clearColor];
bgView.fillColor = [UIColor whiteColor];
bgView.position = CustomCellBackgroundViewPositionSingle;
cell.backgroundView = bgView;
return cell;
}