我没有做任何复杂的事情。只是想在表格单元格上设置字体。如果我在 View Controller 出现后重新加载表格数据,或者滚动表格并且单元格自行更新,则字体显示正常。但是如果我只是在第一次加载时设置 tableview 属性,它就无法正确显示。
代码如下:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellIdentifier = @"listItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [pickerList objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.backgroundColor = [UIColor AMFDarkBlueColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.textLabel.textColor = [UIColor AMFRedColor];
cell.textLabel.font = [UIFont fontWithName:@"MuseoSlab-500" size:cell.textLabel.font.pointSize];
}
就像我说的,如果我在 viewDidAppear
中调用 reloadData
,它就会工作。这似乎是一个不必要的步骤,所以我想确保我没有做错什么。
谢谢
编辑
无论我在 cellForRowAtIndexPath
还是 willDisplayCell
最佳答案
尝试这样做
cell.textLabel.font = [UIFont fontWithName:@"MuseoSlab-500" size:17.0];
关于ios - UITableViewCell 自定义字体仅在表更新后显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14966662/