我有UIViewController,我已经在故事板中添加了一个UITableView,后来我添加了向上滑动手势识别器的视图,但没有发生任何事。滑动垂直手势不工作与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
}
}
工作!,但为什么我应该实现3号 –
,因为在你的tableview它与滚动视图,你正在实施刷卡,所以有两个手势:)然而,如果它是有用的,那么我希望你也会接受我的答案。 :) –
绝对,只需编辑你的答案,并使编号#3的代码更合适! –