【发布时间】:2017-05-24 13:12:00
【问题描述】:
我正在通过 swift3 中的故事板在 uitableview 中实现长按。我在情节提要中只有一个原型单元集。但问题是仅在第一个单元格中检测到长按。其余单元格不听长按手势。
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 开始,它将被放置在它加载到的第一个视图中。
【问题讨论】:
-
您要将手势附加到哪个视图?
-
合适的视图单元格
-
只需将longpressgesture添加到整个表格视图
-
@JitendraModi 谢谢我明白了....
-
根据以下答案,每次调用方法时都会分配 logpress 手势。取而代之的是,您可以直接将手势添加到 tabelview 所以它只会启动一次。并用于所有细胞
标签: ios uitableview swift3 uilongpressgesturerecogni