ios - UITableViewCell 自定义字体仅在表更新后显示

标签 ios objective-c uitableview

我没有做任何复杂的事情。只是想在表格单元格上设置字体。如果我在 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/

相关文章:

iOS - 自定义 AccessoryView 未显示在 UITableViewCell 中

ios - 如何让 reloadData 在 UITableView 上工作

html - input[type=password] IOS 不渲染键盘(Safari+Chrome)

来自字符串的 iOS NSDate 只有时间

iOS; NSAutoreleasePool 过时了吗?

ios - 如何检测 ios 应用程序中的第一次运行?

ios - 隐藏键盘会破坏 TableView 的 segue

objective-c - 这个 gdb 输出是什么意思?

iphone - isEqualToString故障

ios - 异步加载图像到自定义 UITableViewCell 部分工作