当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?
当前回答
快速解决方案,自定义单元:
import Foundation
class CustomTableViewCell: UITableViewCell
{
required init(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?)
{
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = UITableViewCellSelectionStyle.None
}
}
其他回答
我正在用这个,它对我很有用。
cell?.selectionStyle = UITableViewCellSelectionStyle.None
在UITableViewDelegate协议中,你可以使用willSelectRowAtIndexPath方法 如果你不希望行被选中,返回nil。
同样的,你可以使用willDeselectRowAtIndexPath方法并返回nil,如果你不想让行取消选择。
这就是我所使用的,在cellForRowAtIndexPath中编写这段代码。
cell.selectionStyle = UITableViewCellSelectionStyleNone;
试试这个
cell.selectionStyle = UITableViewCellSelectionStyleNone;
and
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
你也可以使用interfacebuilder设置选择样式。
你只需要把这段代码放到cellForRowAtIndexPath中
禁用单元格的选择属性:(在点击单元格时)。
cell.selectionStyle = UITableViewCellSelectionStyle.None
推荐文章
- iPhone上UIView和UILabels的渐变
- keychain上的分发证书中缺少私钥
- 在实现API时,我如何避免在块中捕获自我?
- 如何创建一个Swift Date对象?
- Xcode 4在目标设备上说“finished running <my app>”——什么都没有发生
- 从另一个应用程序打开设置应用程序
- 快速提取正则表达式匹配
- 如何应用梯度的背景视图的iOS Swift应用程序
- 图书馆吗?静态的?动态吗?或框架?另一个项目中的项目
- 如何用SwiftUI调整图像大小?
- Xcode 6 gitignore文件应该包括什么?
- 如何在iPhone/iOS上删除电话号码的蓝色样式?
- 检测视网膜显示
- 如何在UIImageView中动画图像的变化?
- 如何从iPhone访问SOAP服务