我正在通过swift3中的故事板在uitableview中实现长按。故事板中只有一个原型单元格。但问题是长按仅在第一个单元中被检测到。其余的单元没有听到长按手势。UILongPressGestureRecognizer在表格视图单元格中使用时出现问题
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let row = indexPath.row
cell.textLabel?.text = "Label"
return cell
}
@IBAction func longPress(_ guesture: UILongPressGestureRecognizer) {
if guesture.state == UIGestureRecognizerState.began {
print("Long Press")
}
}
控制台中显示的警告是:
的时间,这是绝对不允许,现在执行。从iOS 9.0开始,它将被放入第一个被加载到的视图中。
您将手势附加到哪个视图? –
uitableview cell –
只需将longpressgesture添加到整个tabelview –