【问题标题】:how to highlight multiple rows in a table view using objective-C如何使用objective-C突出显示表格视图中的多行
【发布时间】: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


【解决方案1】:

使用

self.tableView.allowsMultipleSelection = YES;

UITableView 的属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-13
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 2011-08-09
    • 1970-01-01
    • 2016-12-25
    相关资源
    最近更新 更多