我没有做任何复杂的事情。只是试图在表格单元格上设置字体。如果我在视图控制器出现后重新加载表格数据,或者表格滚动并且单元格自行更新,则字体显示正常。但是如果我只是在第一次加载时设置了 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];
}
就像我说的,如果我调用它,它会reloadData
起作用viewDidAppear
。这似乎是一个不必要的步骤,所以我想确保我没有做错什么。
谢谢
编辑
无论我设置字体cellForRowAtIndexPath
还是willDisplayCell