以下代码适用于 iOS6(及之前),但 UITextField 不显示在 iOS7 中...关于如何让 UITextField 在 iOS7 中的 UIAlterView 中显示的任何想法?
UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter ESC Score"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
dialog.tag = 5;
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setKeyboardType:UIKeyboardTypeNumberPad];
[nameField becomeFirstResponder];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 0.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];
为 iOS6 运行的代码显示如下:
iOS7 中的相同代码显示了这一点(注意 UITextField 是如何丢失并且没有键盘):
最佳答案
在 iOS 7 中,您无法轻松更改 UIAlertView 的 View 层次结构。(您也不应该这样做;文档明确告诉您不要这样做。)前往开发者论坛查看有关它的长时间讨论。
在您的情况下,另一种选择是设置 alert.alertViewStyle = UIAlertViewStylePlainTextInput;
这将为您添加一个文本字段。您可以使用 UITextField *textField = [alertView textFieldAtIndex:0];
在 UIAlertView 委托(delegate)回调中访问它。
关于objective-c - 无法在 iOS7 上将 UITextField 添加到 UIAlertView ...在 iOS 6 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18549519/