【发布时间】:2019-08-01 21:31:03
【问题描述】:
我想在点击单元格标签时编辑标签文本(不是didSelectRowAt)。 Taped 标签函数 (toDoItemLabelTapped) 显示 nil。
虽然UITapGestureRecognizer 运行良好,但它不会传递标签文本。
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! ToDoItemsCell
cell.delegate = self
cell.textField.delegate = self
cell.textField.isHidden = true
cell.toDoItemLabel.isUserInteractionEnabled = true
let aSelector : Selector = Selector(("toDoItemLabelTapped"))
var tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
tapGesture.numberOfTapsRequired = 1
cell.addGestureRecognizer(tapGesture)
tapGesture.delegate = self as? UIGestureRecognizerDelegate
tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
return cell
}
这里是函数:
var customTableViewController = ToDoItemsCell()
@objc func toDoItemLabelTapped() {
print(customTableViewController.toDoItemLabel.text)
}
错误如下:
致命错误:在隐式展开可选值时意外发现 nil
如何让点击手势通过单元格的标签文本?
【问题讨论】:
-
使用闭包。
标签: ios swift uitableview uitapgesturerecognizer