首页 > 解决方案 > IOS/Swift:使表格视图单元格不可选择,但表格视图仍可在 Swift 中滚动

问题描述

我想让 tableView 的单元格不可选择,但仍允许滚动。当我放置

 tableView.isUserInteractionEnabled = false

这在某些答案中被推荐viewDidLoad,它可以防止选择但也可以防止滚动。

添加:

 cell.selectionStyle = .none

如下所示cellforrowatindexpath对我没有任何影响。

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        self.tableView.beginUpdates()
        self.tableView.endUpdates()

        if let cell = tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath) as? myMessageCell {
            cell.message = messages[indexPath.row]
            cell.selectionStyle = .none
        }

        return tableView.dequeueReusableCell(withIdentifier: "myMessageCell", for: indexPath)
    }

谁能建议如何在不阻止滚动的情况下阻止选择?

在此先感谢您的任何建议。

标签: iosswifttableview

解决方案


希望你正在寻找这个:

tableView.allowsSelection = false

推荐阅读