我有一个UIViewController,在storyboard中我添加了一个UITableView。后来我给这个视图添加了一个向上滑动的手势识别器,但是没有任何反应。
以下是我的代码:
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
}
}