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];
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];
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..
Xyz answered correctly, but you don't necessarily need to use delegate. You may just connect action from interface builder on "Editing did begin" and write same code there.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString * str = [textField.text stringByReplacingCharactersInRange:range withString:string];
return YES;}
when you start editing use this code to store it ur string