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

标签 ios objective-c cocos2d-iphone

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

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/

相关文章:

ios - 找不到接受 Swift 中提供的参数的 “init” 的重载

ios - 沿贝塞尔路径放置图像

iphone - 子类化 UIView 以在 Quartz 中绘制

iphone - 更改 cocos2D 中 CCSprite 的父级

ios - 当应用程序处于事件状态时,不会在我的 View Controller 中调用 viewWillAppear

ios - 如何从命令行获取设备的iOS版本?

objective-c - iSpeech API弹出窗口

ios - UITableView 以编程方式滚动到元素

ios - ScrollView 滚动和触摸事件从不触发

iphone - 寻找移动 Sprite 和移动图 block map 之间的碰撞