ios - UITableView:仅在编辑模式下显示选定的单元格背景

标签 ios objective-c cocoa-touch uitableview

当我的 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/

相关文章:

ios - 当键盘出现时滚动到底部导致崩溃

ios - Storyboard中的 Facebook SSO 实现 - 登录后出现黑屏

ios - 全局更改符号名称的编译器选项?

iphone - 我可以阻止 UITableViewCell 自动调整其 subview 的大小吗?

ios - 我可以使用 setAnimationRepeatCount : within a UIView animation block?

iOS 8.3 Facebook 错误未登录

ios - 将一个应用划分为多个具有不同UI设计的应用并共享逻辑代码

php - AFNetworking JSON请求不起作用

iphone - 时间计算给出越来越错误的结果

ios - 无法滚动到 UITableView 的底部