我没有做任何复杂的事情。试图设置表格单元格的字体。如果在视图控制器出现后重新加载表格数据,或者表格被滚动并且单元格自身更新,字体显示效果会很好。但是,如果我在第一次加载时只设置了tableview属性,它就不能正确显示。仅在表更新后才显示UITableViewCell自定义字体
下面的代码:
-(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
,这是对我工作的罚款。什么是问题。详细告诉我。 – Nirav 2013-02-19 20:28:36
我必须手动调用viewDidAppear中的reloadData才能显示字体。我认为这会导致数据在视图控制器加载时加载两次,每当视图控制器出现时加载一次。对我来说似乎没有必要。 – Dcritelli 2013-02-19 20:32:05
我仍然建议你在你的单元格初始化中更改你的cell.textLabel.font,否则将设置单元格在屏幕上显示的所有内容。 – Ares 2013-02-19 21:42:14