gpt4 book ai didi

ios - 输入对话框中的 UITextField 未显示

转载 作者:行者123 更新时间:2023-11-28 22:20:38 25 4
gpt4 key购买 nike

我正在实现一个要求输入名称的简单对话框。这是我的代码:

UIAlertView* dialog = [[UIAlertView alloc] init];
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog setMessage:@" "];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];

UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 20.0);
[dialog setTransform: moveUp];
[dialog show];
[dialog release];
[nameField release];

它过去工作正常,但在 iOS 7 中文本字段不显示。谁能帮忙?

最佳答案

这在 iOS7 中不再有效试试这个

  UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"Enter a phone number",nil)  delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",nil) otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert setTag:1];
[[alert textFieldAtIndex:0] setDelegate:self];
[[alert textFieldAtIndex:0] resignFirstResponder];
[[alert textFieldAtIndex:0] setPlaceholder:NSLocalizedString(@"Enter Number here", nil)];
[[alert textFieldAtIndex:0] setKeyboardType:UIKeyboardTypeNumberPad];
[[alert textFieldAtIndex:0] becomeFirstResponder];

[alert show];
[alert release];

您可以根据需要更改键盘类型。

祝你好运:)

关于ios - 输入对话框中的 UITextField 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20513514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com