ios - 在 TableView 上检测滑动手势

标签 ios swift uitableview uigesturerecognizer

有没有办法检测 ViewController 中 TableView 的上下滑动?

ViewDidLoad()中;

    let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector("swipeUp:"))
    let downSwipe = UISwipeGestureRecognizer(target: self, action: Selector("swipeDown:"))

    upSwipe.direction = .Up
    downSwipe.direction = .Down

    tableView.addGestureRecognizer(upSwipe)
    tableView.addGestureRecognizer(downSwipe)

不幸的是,这不起作用。

func swipeDown() {
    print("A")     
}

没有返回。

在 TableView(不是单元格/整体)上检测手势的合适方法是什么?

最佳答案

实现 UIScrollViewDelegate

定义scrollViewDidScroll(_:)

将你的 tableview 的 scrollview 的委托(delegate)设置为你在上面定义的任何对象。

关于ios - 在 TableView 上检测滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36511708/

相关文章:

ios - 试图在我的 UITableView 中返回数组的每个索引

ios - 无法从静态库和包中加载 subview 类和 xib

ios - 如何从其自己的 subview Controller 中解散模态 uitabbarcontroller

ios - 为什么我不能在 Swift 中重新分配实例方法?

ios - 按角度平移点 ios

json - 将 JSON NSData 转换为字典

objective-c - 用户默认值从 Obj C 迁移到 Swift

ios - 获取将插入到 UITableView 中的行的索引

ios - UITableView 中的最后一个单元格获取第一个单元格的属性

ios - JSON数据解析异常 "objectForKey unrecognized selector"