didSelectRowAt 仅在多点触控时调用 [英] didSelectRowAt called only on multitouch

查看:20
本文介绍了didSelectRowAt 仅在多点触控时调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么可以让 UITableViewCell 只检测多点触控?如果我用一根手指点击它不会调用 didSelectRowAtIndex.

What can make UITableViewCell detect only multitouch? If I tap with one finger it doesn't call didSelectRowAtIndex.

这是我的代码:

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

UITableViewCell 类:

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

推荐答案

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

You can handle the behavior of uitableviews's didSelectRowAt method after implementing the delegate methods of gesture recognizer. This prevents the undefined behavior of taps between uiview and tableViewCell and keeps the record of touches.

UIGestureRecognizerDelegate 方法:

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

这篇关于didSelectRowAt 仅在多点触控时调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆