【发布时间】:2016-12-07 13:22:19
【问题描述】:
我有包含视频节目列表的表格视图。当我点击一个程序时,该程序将在该表视图上方的播放器视图中播放。看起来像这样。
我想要做的是在我点击一行后我希望该行中的文本变成红色。我的问题是它不能立即变成红色,但我必须滚动该行的表格视图才能离开屏幕并再次回到屏幕上,然后该选定行中的文本将变为红色。我知道这是 tableview cellForRowAtIndexPath 的行为。所以我在 tableview didSelectRowAtIndexPath 中添加了[self.tableView reloadData],但它不起作用。正如我所说,我必须滚动该选定的滚动屏幕,然后返回屏幕以更改其颜色。我该如何解决这个问题?
下面是相关代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"LiveTableViewCell";
LiveTableViewCell *cell = (LiveTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//...... (more stuff here but not related)
//Color - for one selected/playing
if (programList.programId == self.liveData.programId ) {
[str1 addAttribute:NSStrikethroughColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color
[str1 addAttribute:NSForegroundColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color
}
cell.title.attributedText = str1;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//...... (more stuff here but not related)
[self.tableView reloadData];
}
【问题讨论】:
-
据我所知,您没有通过检查其 indexPath 来设置单元格颜色,而是使用您定义和更新的一些其他值。更新这些 ID 的代码可以在 tableView didSelectRowAtIndexPath 之后运行吗?
标签: ios objective-c uitableview