Я переключаюсь между различными фонами ячейки (белый и светло-серый) и свойствами шрифта (полужирный и обычный) после создания или повторного использования ячейки с помощью следующего кода:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
UIView* cellBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
UIFont *font;
if ([[userModel suspended] boolValue]) {
[cellBackgroundView setBackgroundColor:[UIColor lightGrayColor]];
font = [UIFont italicSystemFontOfSize:[[[cell textLabel] font] pointSize]];
} else {
[cellBackgroundView setBackgroundColor:[UIColor whiteColor]];
font = [UIFont boldSystemFontOfSize:[[[cell textLabel] font] pointSize]];
}
[cell setBackgroundView:cellBackgroundView];
[[cell textLabel] setFont:font];
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];
[[cell textLabel] setText:[NSString stringWithFormat:@"%@, %@",
[userModel familyName], [userModel givenName]]];
[[cell detailTextLabel] setText:[userModel userName]];
return cell;
}
Проблема заключается в том, что если ячейказначение должно быть lightgray и курсив в первом наборе ячеек, отображаемых после загрузки, его фон отображается lightgray (правильно), но его шрифт нормальный (неверно).
Если я прокручиваю вниз и снова отображаю ячейку, она отображается как положено.
Спасибо, Хорхе