iphone中有弹出编辑器功能吗?

时间:2008-11-12 04:56:58

标签: iphone cocoa-touch

我想用编辑框弹出一个简单的对话框,让用户输入一些值,然后返回。我想知道iPhone SDK是否有这种支持。

感谢。

4 个答案:

答案 0 :(得分:7)

我找到了一个解决方案: http://www.iphonedevsdk.com/forum/iphone-sdk-development/1704-uitextfield-inside-uialertview.html

这是适合我的代码。

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[myAlertView setTransform:myTransform];

[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];

答案 1 :(得分:4)

您需要创建弹出窗口(UIAlertView)并将UITextField(或您要使用的任何组件)添加为子视图。 UIAlertView不会自动调整您添加的组件的大小,因此您必须通过向其添加文本来破解它的一部分。该文本将增加弹出窗口的高度,并且如果您的组件没有添加太多隐藏文件。

答案 2 :(得分:1)

将此功能添加到显示警报之前调用的代码中。

  • (void)willPresentAlertView:(UIAlertView *)alertView { alertView.frame = CGRectMake(x,y,width,heigth); }

答案 3 :(得分:1)

调整UIAlertView大小的提示......

正如Milen Milkovski在上面/下面写的那样,如果你为UIAlertView设置一个代表:

UIAlertView* theAlert = [[UIAlertView alloc] initWithTitle:@"Lah"
                                                   message:@"dee dah"
                                                  delegate:self
                                         cancelButtonTitle:nil
                                         otherButtonTitles:nil];
//NSLog(@"Pre Show: alert frame x,y: %f,%f, alert frame width,height: %f,%f",  theAlert.frame.origin.x,theAlert.frame.origin.y, theAlert.frame.size.width, theAlert.frame.size.height);
[retrievingListAlert show];

然后,您可以通过定义以下UIAlertView回调来修改UIAlertView的框架(在委托类中 - 在本例中,因为我们使用self,与创建UIAlertView的类相同):

(void)willPresentAlertView:(UIAlertView *)alertView {
    //NSLog(@"willPresentAlertView: alert frame midx,midy: %f,%f, alert frame width,height: %f,%f",  alertView.frame.origin.x, alertView.frame.origin.y, alertView.frame.size.width, alertView.frame.size.height);
    alertView.frame = CGRectMake( x, y, width, heigth ); 
}

我发现在其他时间设置框架不起作用。看来show函数修改了框架,可能是在对其内容进行自动调整时。