Swift UiTableViewCell在我的主视图控制器长按

问题描述:

重置我有一个按钮,弹出一个对话框有两个按钮和一个tableView。 tableView是使用自定义的UIView显示的,而UITableViewCell也是自定义的。 UITableViewCell由一个自定义复选框和一个UILabel组成。我试图向tableView添加一个点击手势,这样当我点击一行时,它会标记复选框。此功能还挺作品,但是当我按下了更多然后3秒的UITableViewCell重置这个Swift UiTableViewCell在我的主视图控制器长按

UITableViewCell Error ScreenShot

我不知道什么导致此错误。任何帮助,将不胜感激。

这是我在我的ViewController代码,打开弹出对话框:用的tableView

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") 
} 

点触手势功能在我的自定义的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 
    } 
} 

我想你可能需要添加双击手势在你的tableviewcell上,而不是tableview。

+0

我该怎么做呢? – satish99

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

UITableViewDelegate Documentation