【发布时间】:2015-11-25 11:01:14
【问题描述】:
如果我触摸第一行,它将突出显示。如果我触摸第二行,第一行突出显示不存在,第二行在 iOS 的表格视图中突出显示。 我想突出显示(多个)两行。
这是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor grayColor];
cell.selectedBackgroundView = selectionColor;
}
【问题讨论】:
-
你可以这样做 if(indexpath.row==1){Set COlor as per need} else if (indexpath.row==2){Set Color}
-
@Mehul 我想用相同的颜色突出显示两行。如果我触摸行,将调用以下方法“- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath” 这种方法有什么办法吗?
-
不要在每次调用 cellForRowAtIndexPath: 时向单元格添加 UIView 子视图!单元实例会被重用,因此您无需重复替换背景视图实例。只需设置单元格的背景颜色,而不是使用 selectedBackgroundView。
标签: ios objective-c uitableview