2

我需要显示一个 UIAlertView 要求用户更改一些文本,但大多数时候用户会想要:a)保持文本不变或 b)替换整个文本。在极少数情况下,他只想通过附加或修改来更改文本。

因此,为此,我提出了以下代码:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Name for your item"
                                                    message:nil
                                                   delegate:self
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Accept", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alertView textFieldAtIndex:0];
textField.text = @"Some random text";
[alertView show];

UITextRange *textRange = [textField textRangeFromPosition:textField.beginningOfDocument
                                               toPosition:textField.endOfDocument];
[textField setSelectedTextRange:textRange];

这在 iPhone 上运行良好,在显示警报时选择了文本,它按我的预期工作,但在 iPad 上根本没有选择文本。

我做错了什么吗,这是 iOS 上的一个错误,还是这种行为记录在我没有找到的某个地方?

4

1 回答 1

0
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"name" message:@"" delegate:self
                                            cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

alertViewt.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [Renamealert textFieldAtIndex:0];
textField.text=@"XYZZZ   ";
[alertView show];

UITextRange *textRange = [textField textRangeFromPosition:textField.beginningOfDocument
                                               toPosition:textField.endOfDocument];
[textField setSelectedTextRange:textRange];
于 2014-10-16T08:20:40.147 回答