当我的 tableView
不处于编辑模式时,我不希望用户能够触摸单元格并使它们突出显示。但是,因为我已将 allowsSelectionDuringEditing
设置为 YES,用户可以在编辑模式下选择单元格。
如何仅在编辑模式下显示单元格突出显示 View 或颜色?
最佳答案
有趣的场景,幸运的是它就这么简单:
// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row.
// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
return self.isEditing;
}
从 Apple 的评论中可以看出,shouldHighlight 是选择过程的第一步,因此在编辑表格的情况下,这是停止它的地方。
关于ios - UITableView:仅在编辑模式下显示选定的单元格背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16270743/