关于UIAlertView with Textfield ... [英] About UIAlertView with Textfield...

查看:89
本文介绍了关于UIAlertView with Textfield ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码提示 UIAlertView UITextfield

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"New List Item", @"new_list_dialog")
                                                      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)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];

但是我想在用户点击确定后添加一个获取文本字段值,并且用户点击后,我想调用一个方法,如何将其分配给myAlertView?谢谢。

But I would like to add a get the textfield value, after the user click "OK", and after the user click , I want to call a method, how can I assign that to the myAlertView? Thank you.

推荐答案

将文本字段声明为global.And在alertView的方法中单击 - (void)alertView :(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 只需获取文本字段的值并使用它执行所需的操作.....

Declare the text field as global.And in the method of alertView clicked - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex just take the value of the textfield and do the operations you want with it.....

继承修订后的代码

UITextField *myTextField;
...
{

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"New List Item", @"new_list_dialog")
                                                      message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];
}
....
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"string entered=%@",myTextField.text);
}

对于iOS 5及更高版本
您可以使用 alertViewStyle 的属性> UIAlertView

For iOS 5 and later You can use alertViewStyle property of UIAlertView.

请参考Hamed的答案相同

Please refer Hamed's Answer for the same

这篇关于关于UIAlertView with Textfield ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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