ios - 如何禁用 UITableView 选择?

标签 ios uitableview cocoa-touch

当您点击 UITableView 中的一行时,该行会突出显示并被选中。是否可以禁用此功能以便点击一行什么都不做?

最佳答案

您所要做的就是使用以下任一方法在 UITableViewCell 实例上设置选择样式:

objective-C :

cell.selectionStyle = UITableViewCellSelectionStyleNone;

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

swift 2:

cell.selectionStyle = UITableViewCellSelectionStyle.None

swift 3 和 4.x:

cell.selectionStyle = .none

此外,请确保您没有在 TableView 委托(delegate)中实现 -tableView:didSelectRowAtIndexPath:,或者如果您实现了它,则明确排除您不希望有任何操作的单元格。

More info herehere

关于ios - 如何禁用 UITableView 选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/190908/

相关文章:

ios - 即使登录错误也能登录

objective-c - 如何始终使 UIScrollView 可滚动?

ios - 在 UITableViewCell 中显示每个字典值

ios - 我可以在 iOS 中将文件写入应用程序的文档目录吗?

objective-c - 像 Twitter 的 Compose Button 一样的全局/持久 UIBarButtonItem?

ios - 使用 AUTOLAYOUT 和 SIZECLASSES 对齐 View

ios - 具有多个条件的 UITableView filteredArrayUsingPredicate?

ios - 在 Swift 中编辑 TableViewCell 的内容列表

iphone - 允许 UIBarButtonItem 触摸 UINavigationBar 的顶部和底部

ios - 如何使用 Cordova 项目将设置正确添加到 iOS 应用程序?