滑动垂直手势不适用于UITableView [英] Swipe vertical gesture not working with UITableView

查看:163
本文介绍了滑动垂直手势不适用于UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UIViewController,并且在情节提要中向其中添加了UITableView,后来我向视图中添加了向上滑动手势识别器,但没有任何反应.

I have UIViewController and I have added a UITableView to it in the storyboard, later I added a swipe Up gesture recognizer to the view, but nothing happened.

这是我的代码

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {

@IBOutlet weak var tableview: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let swipeRegongnizer = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipeUp))
    swipeRegongnizer.direction = UISwipeGestureRecognizerDirection.up
    swipeRegongnizer.delegate = self
    tableview.addGestureRecognizer(swipeRegongnizer)
}

func handleSwipeUp(gesture: UISwipeGestureRecognizer) {
        print("swiped up")
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    cell.textLabel?.text = "cell\(indexPath.row)"
    return cell
}
}

推荐答案

1..实现UIGestureRecognizerDelegate. 2.设置代表.

1. Implement UIGestureRecognizerDelegate. 2. set delegate.

    yourGesture.delegate = self

3..在各自的swift文件中添加以下功能.

3. add the following function in your respective swift file.

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
}

这篇关于滑动垂直手势不适用于UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆