У меня есть вид таблицы, и я хочу знать, как я могу изменить цвет текста выбранной строки, скажем, на красный?Я попробовал этот код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell= [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
cell.text = [localArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
cityName = [localArray objectAtIndex:indexPath.row];
UITableViewCell* theCell = [tableView cellForRowAtIndexPath:indexPath];
theCell.textColor = [UIColor redColor];
//theCell.textLabel.textColor = [UIColor redColor];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
(1) Когда я выбираю какую-либо строку, цвет текста меняется на красный, но когда я выбираю другую, то текст ранее выбранной строки остается красным.как я могу решить это?
(2) Когда я прокручиваю таблицу, цвет текста меняется на черный, как решить эту проблему?
Спасибо ..