【发布时间】:2016-10-01 12:03:38
【问题描述】:
什么可以让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)
}
}
【问题讨论】:
-
为什么将代码放在 DispatchQueue.main.async 中?删除它并尝试。
-
我已经添加了它,因为如果我不这样做,它会在提交 VC 之前有很长的延迟(我很久以前就找到了这个解决方案)并且 100% 确定这不是真正的问题。
-
在我的情况下,相同的代码运行良好
-
你的意思是双击单元格..?
-
是的,有可能,但您必须实现手势识别器,这可能会导致禁用
didSelectRowAtIndexPath方法..
标签: ios swift uitableview didselectrowatindexpath