How to make UITextField’s text selected programmatically ?



For making UITextField’s text selected programmatically you need to set the UITextField’s delegate linke below :

txt.delegate = self;

and then put following code in textFieldDidBeginEditing

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


And don’t forget to add delegate in .h

@interface ViewController : UIViewController <UITextFieldDelegate>

Hope this will help somebody.

Happy Coding !!!


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box