Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 长按后,Swift UiTableViewCell将重置_Ios_Swift_Uitableview_Uiview_Uitapgesturerecognizer - Fatal编程技术网

Ios 长按后,Swift UiTableViewCell将重置

Ios 长按后,Swift UiTableViewCell将重置,ios,swift,uitableview,uiview,uitapgesturerecognizer,Ios,Swift,Uitableview,Uiview,Uitapgesturerecognizer,在我的主视图控制器中,我有一个按钮,可以弹出一个对话框,其中有两个按钮和一个表视图。tableView使用自定义UIView显示,UITableViewCell也是自定义的。UITableViewCell由一个自定义复选框和一个UILabel组成。我正在尝试向tableView添加一个点击手势,以便当我单击一行时,它会标记该复选框。这项功能可以正常工作,但当我按下超过3秒时,UITableViewCell会重置为此 我不知道是什么导致了这个错误。任何帮助都将不胜感激 以下是我在我的ViewCo

在我的主视图控制器中,我有一个按钮,可以弹出一个对话框,其中有两个按钮和一个表视图。tableView使用自定义UIView显示,UITableViewCell也是自定义的。UITableViewCell由一个自定义复选框和一个UILabel组成。我正在尝试向tableView添加一个点击手势,以便当我单击一行时,它会标记该复选框。这项功能可以正常工作,但当我按下超过3秒时,UITableViewCell会重置为此

我不知道是什么导致了这个错误。任何帮助都将不胜感激

以下是我在我的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
    }
}

我认为您可能需要在tableview单元格上添加点击手势,而不是在tableview上

我认为您可能需要在tableview单元格上添加点击手势,而不是在tableview上

您只需要让ViewController实现UITableViewDelegate。
didSelectRowAtIndexPath
有一个回调方法,您可以在其中设置访问单元格属性的逻辑,例如自定义复选框。不需要点击手势识别器,因为这是本机提供的功能


您只需要让ViewController实现UITableViewDelegate。
didSelectRowAtIndexPath
有一个回调方法,您可以在其中设置访问单元格属性的逻辑,例如自定义复选框。不需要点击手势识别器,因为这是本机提供的功能


我该怎么做?我该怎么做?