到目前为止似乎没有任何效果

到目前为止似乎没有任何效果

本文介绍了如何检测 UITableView 上的触摸,到目前为止似乎没有任何效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测UITableView 上的触摸?我在这个线程中尝试了解决方案.我在同一个 UIViewController 中有我的 tableView 和一个 scrollView,并带有约束,因此对 tableView 进行子类化很复杂>.
未调用 touches 方法:

How can I detect a touch on a UITableView? I tried the solutions in this thread. I have my tableView and a scrollView in the same UIViewController with a constraint, so it is complicated to subclass the tableView.
The touches methods are not called:

class ViewController: UIViewController, UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var verticalSpacing: NSLayoutConstraint!
    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var tableView: UITableView!


override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    super.touchesBegan(touches, withEvent: event)
    println("touch began")
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
    super.touchesMoved(touches, withEvent: event)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    super.touchesEnded(touches, withEvent: event)
    println("touch ended")
}
override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
    super.touchesCancelled(touches, withEvent: event)
}

我补充说:

tableView.userInteractionEnabled = true
tableView.canCancelContentTouches = false //or true is the same

但它不会改变任何东西.scrollViewtableView 同时可见,但它们不重叠.

but it doesn't change anything. The scrollView is visible at the same time as the tableView, but they are not overlapping.

推荐答案

有一些方法在使用 UITableView 时很有用,可以检测滚动视图的变化.这些可能对您有用.

There are methods that can be useful when working with UITableView that detect changes to the scrollview. These may be useful for you.

例如

override func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    println("Ended decelerating")
}

override func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    println("Ended dragging")
}

这篇关于如何检测 UITableView 上的触摸,到目前为止似乎没有任何效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:44