[yourtextField becomeFirstResponder]; //puts cursor on text field
[yourtextField selectAll:nil]; //highlights text
[yourtextField selectAll:self]; //highlights text and shows menu(cut copy paste)
斯威夫特
yourTextField.becomeFirstResponder() //puts cursor on text field
yourTextField.selectAll(nil) //highlights text
yourTextField.selectAll(self) //highlights text and shows menu(cut copy paste)
UIWindow *window = [[[UIApplication sharedApplication] windows] firstObject];
[window addSubview:theAlertView]; // textfield must be added as a subview of screen first
UITextField *textField = theAlertView.textField;
[textField becomeFirstResponder]; // then call to show keyboard and cursor
UITextRange *range = [textField textRangeFromPosition:textField.beginningOfDocument toPosition:textField.endOfDocument]; // at this time, we could get beginningOfDocument
[textField setSelectedTextRange:range]; // Finally, it works!!!