Yony
Yony

Reputation: 680

objective c textField: selectAll text doesn't always work

I implemented this in the UITextField delegate:

-(void)textFieldDidBeginEditing:(UITextField *)iTextField {
    [iTextField selectAll:iTextField];
}

My text field contain text. When tapping on it, the keyboard goes up and all text selected. when dismissing the keyboard and tapping again, no text selected (just blinking cursor). when dismissing the keyboard and tapping again, all text selected again.

Any clue why does no text selected at the second tap?

Upvotes: 4

Views: 2610

Answers (2)

Bill Chan
Bill Chan

Reputation: 3455

I call selectAll in viewDidAppear works.

Upvotes: 0

Camo
Camo

Reputation: 1778

have you tried with this?

textField.selectedTextRange = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument];

EDIT 1: Now is going to work :), this call will be at the end of the queue

[textField performSelector:@selector(selectAll:) withObject:nil afterDelay:0.0];

Upvotes: 9

Related Questions