Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UITextField's text selected programmatically

I want to select all text from the UITextField selected when i start editing. I tried the below code but this doesn't work.

[txt selectAll:self];
like image 466
iBhavik Avatar asked Apr 27 '12 11:04

iBhavik


People also ask

How do you select all input fields of text?

The HTMLInputElement. select() method selects all the text in a <textarea> element or in an <input> element that includes a text field.

How do you select all text in TextField Flutter?

On native platforms and browsers using a triple click (with a mouse) on text in a textfield one selects all text in the textfield.

Which method is used to get the data from TextField?

Notice the use of JTextField 's getText method to retrieve the text currently contained by the text field.

What is TextField Flutter?

TextField in Flutter is the most commonly used text input widget that allows users to collect inputs from the keyboard into an app. We can use the TextField widget in building forms, sending messages, creating search experiences, and many more. By default, Flutter decorated the TextField with an underline.


1 Answers

Please check where you have placed it... Try putting the code above in

       -(void)textFieldDidBeginEditing:(UITextField *)textField
        {
           [textField selectAll:self];

         }

And also txt must be UITextField. Also do not forget to set the delegate for txt as

        txt.delegate = self;

where you have declared it and add UITextFieldDelegate in .h as

       @interface ViewController : UIViewController <UITextFieldDelegate>

This will definitely work....It worked for me..

like image 58
Minakshi Avatar answered Oct 14 '22 20:10

Minakshi