【发布时间】:2017-04-01 06:22:40
【问题描述】:
我在 TableViewCell 上有故事板 segue,我用它在didSelectRowAt 方法中单击单元格时转移到另一个 VC。现在我双击TapGestureRecognizer 来处理对单元格的轻敲。问题是单击时,segue 正在执行,而双击不起作用。双击可以很好地单击单元格外。到目前为止,有可能用我的代码以某种方式解决这个问题吗?或者我需要删除 segue 并分别处理单击和双击。
感谢您的任何建议
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(handleDoubleTap))
doubleTap.numberOfTapsRequired = 2
view.addGestureRecognizer(doubleTap)
}
func handleDoubleTap(recognizer: UIGestureRecognizer) {
let p = recognizer.location(in: tableView)
let indexPath = tableView.indexPathForRow(at: p)
if let _ = indexPath {
tableView.deselectRow(at: indexPath!, animated: true)
update(index: (indexPath?.row)!, isFinished: true)
}
print ("doubke")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "showSingleTask") {
if let indexPath = tableView.indexPathForSelectedRow {
let nav = segue.destination as! UINavigationController
let destinationVC = nav.topViewController as! ShowTaskVC
destinationVC.singleTask = tasks[indexPath.row]
}
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
self.selectedTask = tasks[indexPath.row]
}
【问题讨论】:
-
所以我有一个问题.. 你想双击单元格以便它调用 segue 吗?也许提供更多细节会有所帮助。
-
禁用默认点击单元格并在单元格上添加单击手势,就像添加双击一样。
-
@JArango 我想双击单元格以调用 handleDoubleTap 方法并单击单元格以执行 segue,我想知道是否可以使用 didSelectRowAt 方法或我需要添加单击手势如上所述
标签: swift uitableview swift3 uitapgesturerecognizer