How to highlight text automatically inside an UIAlertView text field
I have an UIAlertView with a textfield that shows a default value and two buttons, one to cancel and the other one to confirm. What I am trying to do is that when the alert view is popped up the default value is highlighted so the user can overwrite the whole value faster than manually erasing it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue",nil];
[alert addTextFieldWithValue:@"87893" label:@"value"];
UITextField *textField = [alert textField];
campoTexto.highlighted = YES;
campoTexto.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
[alert show];
[alert release];
}
For some reason there开发者_如何学编程 is a highlighted attribute for the textfield but it doesn't seem to work and there is no trail of that attribute in the Class documentation.
I had a similar situation. I wanted to prompt the user for a new value, however, I didn't want the original value to disappear, but I also didn't want the text appending to the value.
I ended up calling
[alertView show];
[textField selectAll:self];
One thing you might also look out for is you are setting keyboardType and highlighted on campoTexto which is not the text field you're getting from the alert view.
加载中,请稍侯......
精彩评论