Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect tap on UITextField?

I have a UITextField that has User Interaction Disabled. So if you tap on this text field, nothing happens. Normally to check if a text field was tapped Id try the delegate methods, but I cannot because user interaction is disabled. Is there any way I can check if the text field was tapped/touched? I change another element to hidden = no; when it is tapped so I was wondering if its even possible enabling user interaction.

like image 205
Josue Espinosa Avatar asked Sep 10 '13 22:09

Josue Espinosa


People also ask

What is UITextField in swift?

An object that displays an editable text area in your interface.

How do you dismiss a keyboard in Swift?

Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing . Causes the view (or one of its embedded text fields) to resign the first responder status.


1 Answers

Best option is to turn on User Interaction and disable edit action using delegate method.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
     return NO;
} 

You can call your method inside that function to detect tap.

like image 186
Grzegorz Krukowski Avatar answered Oct 14 '22 00:10

Grzegorz Krukowski