gpt4 book ai didi

ios - didSelectRowAt 仅在多点触控时调用

转载 作者:搜寻专家 更新时间:2023-11-01 07:19:51 25 4
gpt4 key购买 nike

什么可以让 UITableViewCell 只检测多点触控?如果我用一根手指点击,它不会调用 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)
}
}

最佳答案

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

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

关于ios - didSelectRowAt 仅在多点触控时调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39806403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com