【发布时间】:2023-03-23 20:00:01
【问题描述】:
在我的主视图控制器中,我有一个按钮,它会弹出一个带有两个按钮和一个 tableView 的对话框。 tableView 正在使用自定义 UIView 显示,并且 UITableViewCell 也是自定义的。 UITableViewCell 由一个自定义复选框和一个 UILabel 组成。我正在尝试向 tableView 添加一个点击手势,以便当我单击一行时它会标记该复选框。这个功能有点用,但是当我按下超过 3 秒时,UITableViewCell 会重置为这个
UITableViewCell Error ScreenShot
我不知道是什么导致了这个错误。任何帮助将不胜感激。
这是我在 ViewController 中打开弹出对话框的代码:
func locationButtonPressed(sender: UIBarButtonItem) {
// Create a custom view controller
let vc = RadiusViewController(nibName: "RadiusViewController", bundle: nil)
// Create the dialog
let popup = PopupDialog(viewController: vc, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)
// create first button
let cancelButton = CancelButton(title: "Cancel", height: 60, dismissOnTap: true) {
print("Popup Canceled")
}
// create second button
let okButton = DefaultButton(title: "Ok", height: 60, dismissOnTap: true) {
print("Ok button pressed")
}
// add buttons to dialog
popup.addButtons([cancelButton, okButton])
// present dialog
self.present(popup, animated: true, completion: nil)
print("location button pressed")
}
使用 tableView 在我的自定义 UIView 中点击手势功能:
override func viewDidLoad() {
super.viewDidLoad()
...code
let tap = UITapGestureRecognizer(target: self, action: #selector(tableTapped))
self.tableView.addGestureRecognizer(tap)
}
func tableTapped(tap:UITapGestureRecognizer) {
let location = tap.location(in: self.tableView)
let path = self.tableView.indexPathForRow(at: location)
if let indexPathForRow = path {
self.tableView(self.tableView, didSelectRowAt: indexPathForRow)
print("Tapped on the table")
} else {
// handle tap on empty space below existing rows however you want
}
}
【问题讨论】:
标签: ios swift uitableview uiview uitapgesturerecognizer