Table 当我设置 delaysContentTouches = false 时,静态单元格不会滚动

Table with static cells won't scroll when I set delaysContentTouches = false

问题:突出显示与滚动

当我轻轻点击它们时,单元格内的按钮没有突出显示。我必须用力点击很长时间才能看到按钮的点击状态。

所以我这样做是为了在 viewDidLoad():

   for index in tableView.subviews {
        if (index.isKindOfClass(UIScrollView)) {
            let scrollViewFound = index as! UIScrollView
            scrollViewFound.delegate = self
            scrollViewFound.delaysContentTouches = false
            scrollViewFound.canCancelContentTouches = true
            scrollViewFound.scrollEnabled = true
        }
    }

这样按钮会正确突出显示,但随后 我无法向上或向下滚动 table,除非我从其中一个空单元格开始拖动 --> userInteractionEnable = false 在空单元格中


我需要的:

既能突出显示按钮又能滚动table。 甚至可以同时拥有可滚动视图和突出显示的按钮吗?


我试过的

我试过调用这个函数:

func touchesShouldCancelInContentView(view: UIView) -> Bool {
    print("touchesShouldCancelInContentView happening---------")
    return true
}

永远不会被调用。我尝试覆盖但它给出了一个错误:

Method does not override any method from its superclass

这很奇怪,因为 UITableViewController 继承自 UIScrollView。我还尝试将 UIScrollViewDelegate 添加到 class 定义中,但当然它会给出另一个错误,即这是多余的。


额外信息

class是这样声明的:

class Settings: UITableViewController, UITextFieldDelegate { ...

tableView 由静态单元格组成

细胞:

Maybe it is relevant to say that when user clicks on any cell didSelectRowAtIndexPath it will call a function to dismiss the keyboard.

您尝试将 class 替换为错误的 class,这就是它不起作用的原因。您必须 class UITableView class 本身,而不是 UITableViewController。 您可以尝试以下操作吗?

- 第一

Subclass TableView class 以覆盖 touchesShouldCancelInContentView 函数。

class UIDraggableTableView: UITableView {

    override func touchesShouldCancelInContentView(view: UIView) -> Bool {
        if (view.isKindOfClass(UIButton)) {
            return true
        }
        return super.touchesShouldCancelInContentView(view)
    }
}

- 第二

在您的 TableViewController class 中,当调用 viewDidLoad() 时,在 super.viewDidLoad() 之后附加以下内容:

self.tableView = DraggableTableView()

这应该可以解决您的问题。

部分答案来自 this Whosebug post