Ios didSelectRowAt仅在多点触控上调用

Ios didSelectRowAt仅在多点触控上调用,ios,swift,uitableview,didselectrowatindexpath,Ios,Swift,Uitableview,Didselectrowatindexpath,什么可以使UITableViewCell仅检测多点触摸?如果我用一个手指点击,它不会调用didselectrowatinex 这是我的密码: func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "bookingSettingsCe

什么可以使
UITableViewCell
仅检测多点触摸?如果我用一个手指点击,它不会调用
didselectrowatinex

这是我的密码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "bookingSettingsCell", for: indexPath) as! SettingsTableViewCell
    if indexPath.row < 3 {
        cell.settingSwitch.removeFromSuperview()
    }
    cell.settingTitle.text = dataForSetting[indexPath.row].first
    if dataForSetting[indexPath.row].last != "Pencil" {
        cell.settingValue.isHidden = true
        cell.settingChangable.isHidden = true
        cell.settingSwitch.isHidden = false
    }
    return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    DispatchQueue.main.async(execute: {
        if indexPath.row < 3 {
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "DatePicker") as! DatePickerViewController
            destinationVC.modalPresentationStyle = .overCurrentContext
            destinationVC.delegate = self
            self.present(destinationVC, animated: true, completion: nil)
        }
    })
}

我认为问题不在于didSelectRowAt,而在于UITableViewCell。。。 设计xib时是否使用约束逻辑? 可能是某些对象(标签或图像视图)造成触摸问题。。。
查看您的约束或直接在脚本的uitableView中设计tableViewCell。

我发现发生这种情况是因为我在superview中添加了
UITapgestureRecognitizer
,以便在触摸时隐藏键盘。但实际上还是不明白为什么在这种情况下,它与多点触控一起工作?我建议我的错误应该阻止所有点击事件。

在实现手势识别器的委托方法后,您可以处理
uitableview的
didSelectRowAt
方法的行为。这可以防止在
uiview
tableViewCell
之间点击的未定义行为,并保留触摸记录

UIgestureRecognitzerDelegate方法:

class SettingsTableViewCell: UITableViewCell {
@IBOutlet var settingTitle: UILabel!
@IBOutlet var settingChangable: UIImageView!
@IBOutlet var settingValue: UILabel!
@IBOutlet var settingSwitch: UISwitch!

    override func awakeFromNib() {
        super.awakeFromNib()
        settingSwitch.transform = CGAffineTransform(scaleX: 0.65, y: 0.60)
    }
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    println("in shouldReceiveTouch")
    gestureRecognizer.delegate = self
    if (touch.view == tableView){
        println("touching tableView list")
        return false
    }
    else{
        println("touching elsewhere")
        return true
    }
}

您可以通过在类中添加ui手势识别器委托来解决此问题。在类中添加UIgestureRecognitizerDelegate。遵循以下步骤:-

/*

注意:-现在确定您是在点击tableView还是在其他地方,您必须像这样实现此手势委托

//马克:-代表们做手势

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
    // if user touch the tableview then below condition will be true
    if touch.view != nil && (touch.view!.isDescendantOfView(tableViewName)) {
        return false
    }
    return true
}
希望它对你有用

提前谢谢


*/

您可以通过删除视图中的所有手势来检查这是否是由于任何手势造成的,如下所示,然后重试

view.gestureRecognizers?.removeAll()

最好找到导致问题的确切姿势并正确处理。

为什么要将代码放在DispatchQueue.main.async中?删除它并尝试。我添加了它,因为如果我不添加它,它在呈现VC之前会有很长的延迟(我很久以前就发现了这个解决方案),并且100%确定这不是真正的问题。同样的代码在我的情况下工作得很好。你是说像双击单元格之类的东西?是的,这可能是可能的,但您必须实现手势识别器,这可能会导致禁用
didSelectRowAtIndexPath
方法..我在脚本中设计了它。问题是,据我所知,它要么检测触摸(一切正常),要么不检测(一些视图叠加等),但它只检测多点触摸,这很奇怪。
view.gestureRecognizers?.removeAll()