我沒有做任何複雜的事情。試圖設置表格單元格的字體。如果在視圖控制器出現後重新加載表格數據,或者表格被滾動並且單元格自身更新,字體顯示效果會很好。但是,如果我在第一次加載時只設置了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