DidSelectRowAt called only on multi-touch

What can UITableViewCell detect only multitouch? If I touch with one finger, it does not call didSelectRowAtIndex .

Here is my code:

 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:

 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) } } 
+1
ios uitableview swift didselectrowatindexpath
source share
4 answers

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

UIGestureRecognizerDelegate Method:

 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 } } 
+2
source share

I think the problem is not in didSelectRowAt, but in UITableViewCell ... do you use the constraint logic when designing xib? It is possible that some kind of object (label or imageView) creates a touch problem ... view your restriction or create your tableViewCell directly in the uitableView from the storyboard.

0
source share

I realized that this was because I added the UITapGestureRecognizer to my supervisor so that I could hide the keyboard by touch. But I still don’t really understand why in this case he worked with multitouch? I would suggest that my error should block all click events.

0
source share

You can solve this problem by adding the UIGesture recognizer delegate class to the class. Add UIGestureRecognizerDelegate to your class. Follow these steps: -

/ *

 class SignupInstructorViewController: UIViewController, UIGestureRecognizerDelegate 

Note: - Now, to determine if you are clicking on the tableView or where else you should implement this delegate of this gesture like this.

// MARK: - delegates with gestures

 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 } 

HopeFully, it will work for you.

Thanks at Advance.

* /

0
source share

All Articles