当你点击UITableView中的一行时,该行会高亮显示并被选中。是否有可能禁用这个,所以点击一行什么都不做?
当前回答
你可以在(iOS) Xcode 9, Swift 4.0中使用以下代码禁用表格单元格高亮显示
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OpenTbCell") as! OpenTbCell
cell.selectionStyle = .none
return cell
}
其他回答
禁用UITableView中所有uitableviewcell的选择
tableView.allowsSelection = false
禁用特定uitableviewcell的选择
cell.selectionStyle = UITableViewCell.SelectionStyle.none
在UITableViewDataSource协议中,在方法cellForRowAt中添加:
let cell = tableView.dequeueReusableCell(withIdentifier: "YOUR_CELL_IDENTIFIER", for: indexPath)
cell.selectionStyle = .none
return cell
OR
你可以到故事板>选择单元格>身份检查器>选择,从下拉菜单中选择none。
你可以在(iOS) Xcode 9, Swift 4.0中使用以下代码禁用表格单元格高亮显示
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OpenTbCell") as! OpenTbCell
cell.selectionStyle = .none
return cell
}
斯威夫特3,4和5
更好的做法是,在UITableViewCell中编写代码
例如,你有名为MyCell的UITableViewCell, 在awakeFromNib中只写self。selectionStyle = .none
完整的例子:
class MyCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
self.selectionStyle = .none
}
}
我正在用这个,它对我很有用。
cell?.selectionStyle = UITableViewCellSelectionStyle.None
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- Swift:声明一个空字典
- 在成功提交我的应用程序后,“太多符号文件”
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 如何从UIImage (Cocoa Touch)或CGImage (Core Graphics)获取像素数据?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- CFNetwork SSLHandshake iOS 9失败
- 请求失败:不可接受的内容类型:文本/html使用AFNetworking 2.0
- 缺少推荐的图标文件-该包不包含iPhone / iPod Touch的应用程序图标,像素为“120x120”,png格式
- 以编程方式创建segue