我有一个简单的问题UITableViewCell
。 我想要的是改变选定单元格的文字颜色。 在我cellForRowAtIndexPath
方法,我设置:UITableView单元格textLabel颜色
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;
}
它的工作原理,但滚动的tableview时,颜色变回。
怎么样声明一个NSIndexPath * urIndexPath;在你的.h?然后在你的didSelecteRowAtIndexPath方法中,将所选单元格的indexPath传递给urIndexPath,然后重载数据以更新UI,在你的cellForRowAtIndexPath中,比如说,如果urIndexPath是== indexPath {set color to orange; } else {任何颜色默认情况下} – janusbalatbat 2012-03-16 07:13:22
@Akhildas当你滚动tableView cellForRowAtIndex:方法将被调用always.But不是其他方法,你可以调用“WillSelectRowAtIndexPath”方法在你“cellForRowAtIndex:”方法来使它作品 – 2012-03-16 07:15:46