如何禁用 UITableView 选择? [英] How can I disable the UITableView selection?

查看:34
本文介绍了如何禁用 UITableView 选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您点击 UITableView 中的一行时,该行会突出显示并被选中.是否可以禁用此功能以便点击一行没有任何作用?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?

推荐答案

对我来说,以下效果很好:

For me, the following worked fine:

tableView.allowsSelection = false

这意味着 didSelectRowAt# 根本行不通.也就是说,触摸桌子的一行,这样,绝对不会做任何事情.(因此,显然,永远不会有选定的动画.)

This means didSelectRowAt# simply won't work. That is to say, touching a row of the table, as such, will do absolutely nothing. (And hence, obviously, there will never be a selected-animation.)

(请注意,如果在单元格上有 UIButton 或任何其他控件,当然这些控件仍然可以工作.您碰巧在表格单元格上拥有的任何控件都与UITableView 允许您使用 didSelectRowAt#.)选择一行"的能力.)

(Note that if, on the cells, you have UIButton or any other controls, of course those controls will still work. Any controls you happen to have on the table cell, are totally unrelated to UITableView's ability to allow you to "select a row" using didSelectRowAt#.)

另一点需要注意的是:当 UITableView 处于编辑模式时,这不起作用.要在编辑模式下限制单元格选择,请使用以下代码:

Another point to note is that: This doesn't work when the UITableView is in editing mode. To restrict cell selection in editing mode use the code as below:

tableView.allowsSelectionDuringEditing = false 

这篇关于如何禁用 UITableView 选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆