Textfield with calender icon for date picker while tap calender icon want to display datepiker iOS swift
Solution:
Add tap gesture to the imageview in tableview cell..
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
cell.calenderView.addGestureRecognizer(tapGesture)
Gesture function will be like this. dateTF is then textfiled that had datepicker as inputview.
If you call becomeFirstResponder() for textfield while tap on the imageview it will be achieved easily...
@objc func handleTap(_ gestureRecognizer: UITapGestureRecognizer) {
let tapLocation = gestureRecognizer.location(in: tableview)
if let indexPath = tableview.indexPathForRow(at: tapLocation) {
if let cell = tableview.cellForRow(at: indexPath) as? myCell {
cell.dateTF.becomeFirstResponder()
}
}
}
Comments
Post a Comment