Iphone alertview中的Textfield在ios7中不工作?

Iphone alertview中的Textfield在ios7中不工作?,iphone,ios,ipad,Iphone,Ios,Ipad,我有一个应用程序,我在其中使用特定的设计是有原因的。我在警报视图中的otherbutton上方放置了一个文本字段,带有背景图像。在ios 6版本中,一切正常 UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"fdhdj" message:@" hdfjkhfjkhdk" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@" ",@"cancel",nil]; av.a

我有一个应用程序,我在其中使用特定的设计是有原因的。我在警报视图中的otherbutton上方放置了一个文本字段,带有背景图像。在ios 6版本中,一切正常

UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"fdhdj" message:@" hdfjkhfjkhdk" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@" ",@"cancel",nil];
     av.alertViewStyle = UIAlertViewStylePlainTextInput;
 namefield = [[UITextField alloc] initWithFrame:CGRectMake(10.0,43.0, 264.0, 44.0)];
    namefield.borderStyle = UITextBorderStyleNone;
    namefield.background = [UIImage imageNamed:@"text_field_default.png"];
    namefield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    namefield.textAlignment = UITextAlignmentCenter;
    //[namefield setBackgroundColor:[UIColor whiteColor]];
    [av addSubview:namefield];
    [namefield release];
    av.tag=12;
    av.delegate=self;  
    [av show];

    [av release];
但是现在在ios 7中,我听说你不能轻易改变UIAlertView的视图层次结构。 这种情况下的一个备选方案是设置

alert.alertViewStyle=UIAlertViewStylePlainTextInput

但是我们可以在任何我们想要的地方添加文本字段吗?就像我的第一个按钮上面的情况一样。有人能帮我吗

 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Student Name" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save",nil];

 [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
 [alertView show];

我曾经这样做过,它工作得很好

这是我在iOS7中支持addSubview和alertView的组件

-自定义警报视图,允许您将视图添加为主要内容


您的问题的简单答案是否定的,您不能更改
UIAlertViewStylePlainTextInput的
测试字段中的任何内容,您不应该这样做

这是来自苹果的:

UIAlertView类旨在按原样使用,而不是按原样使用 支持子类化。此类的视图层次结构是私有的,并且 不能修改

不幸的是,你听到的我听说你不能轻易改变UIAlertView的视图层次结构是错误的,你根本不能改变iOS7中
UIAlertView
的视图层次结构


web上有一个很好的替代方案,您可以签入

您无法轻松更改iOS 7中UIAlertView的视图层次结构。(您也不应该这样做;文档明确告诉您不要这样做。)前往开发人员论坛,查看关于它的长时间讨论


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

为什么不做你自己的UIView层次结构,你可以完全控制它,而不是愚弄UIAlertView.:“此类的视图层次结构是私有的,不能修改。”,这是您通过添加子视图所做的操作。