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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift