У меня есть простая проблема с UITableViewCell
.
То, что я хочу, это изменить цвет текста выбранной ячейки.
В моем методе cellForRowAtIndexPath
я установил:
cell.textLabel.textColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.highlightedTextColor = [UIColor orangeColor];
Если selectionStyle
равно UITableViewCellSelectionStyleNone
, highlightedTextColor
не изменится.
Поэтому я использую эти два метода для установки цвета текста:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor orangeColor];
return indexPath;
}
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView cellForRowAtIndexPath:indexPath].textLabel.textColor = [UIColor whiteColor];
return indexPath;
}
Работает, но при прокрутке табличного вида цвет меняется обратно.