【发布时间】:2011-08-16 00:16:33
【问题描述】:
我有一个表格视图,我想知道如何更改所选行的文本颜色,比如 Red ?我试过这段代码:
- (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) 当我滚动表格文本颜色变为黑色时如何解决?
谢谢..
【问题讨论】:
标签: ios objective-c iphone uitableview