无法在iOS7上将UITextField添加到UIAlertView ...适用于iOS 6 [英] Unable to add UITextField to UIAlertView on iOS7...works in iOS 6

查看:129
本文介绍了无法在iOS7上将UITextField添加到UIAlertView ...适用于iOS 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码适用于iOS6(以及之前),但UITextField不会显示在iOS7中...有关如何让UITextField显示在iOS7中的UIAlterView中的任何想法吗?

The code below works on iOS6 (and before) but the UITextField does not display in iOS7...any ideas on how to get a UITextField to display in an UIAlterView in iOS7?

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的代码运行显示:

Code run for iOS6 displays this:

iOS7中的相同代码显示这个(注意UITextField是如何丢失的,没有键盘):

same code in iOS7 displays this (notice how UITextField is missing and there is no keyboard):

推荐答案

您无法在iOS 7中轻松更改UIAlertView的视图层次结构(你也不应该;文件明确告诉你不要这样做。)前往开发者论坛,看看有关它的长篇讨论。

You can't easily alter the view hierarchy of a UIAlertView in iOS 7. (Nor should you; the documentation specifically tells you not to.) Head over to the developer forums to see a long discussion about it.

在你的情况下,另一种选择是设置 alert.alertViewStyle = UIAlertViewStylePlainTextInput; 这将为您添加一个文本字段。您可以使用 UITextField * textField = [alertView textFieldAtIndex:0]; ;

One alternative in your case is to set alert.alertViewStyle = UIAlertViewStylePlainTextInput; This will add a text field for you. You can access it in the UIAlertView delegate callback by using UITextField *textField = [alertView textFieldAtIndex:0];.

这篇关于无法在iOS7上将UITextField添加到UIAlertView ...适用于iOS 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆