是否可以突出显示多个 UITableViewCell?像过滤表之类的东西。如果用户点击第 0 行,该行就会突出显示。然后用户点击第 1 行,该行也会突出显示,但第 0 行也保持突出显示。我还没有看到任何这方面的例子。
我有一个字典,其中包含 5 个可以选择的项目,其值为 yes 或 no 来跟踪哪些项目被突出显示。
我使用了 (UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
并将其设置为 nil
但现在我无法取消选择行。请问有什么帮助吗?
最佳答案
要实现这一点,您可以做的是跟踪所选索引并相应地更改表 viewCell 的背景颜色,例如:
将数组声明为 SelectedIndexes
然后在您的 didSelectRowAtIndex 方法中执行此操作:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if([selectedIndex containObject :indexPath]){
[selectedIndexes removeObject:indexPath];
}else{
[selectedIndexes addObject:indexPath];
}
[tableView reloadData];
然后在您的 CellForRowAtIndexPath 方法中执行此操作
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if([selectedIndex containObject :indexPath]){
cell.backgroundColor=highlightedColor; }其他{
cell.backgrounfColor=NormalColor;
}
} 希望这有帮助
关于iOS高亮多个UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147727/