【问题标题】:How to return keyboard for UITextField in UIAlertview in iphone?如何在 iphone 的 UIAlertview 中返回 UITextField 的键盘?
【发布时间】:2012-06-28 15:09:03
【问题描述】:

我有一个 UIAlertView,其中包含一个带有确定和取消按钮的 UITextField。当我单击确定按钮时,我正在调用 webService。我想在调用 web 服务之前返回键盘。直到响应不是来自 web 服务,键盘才会返回。由于在加载 web 服务期间用户看不到半屏。这是我做的代码。

UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Forgot Password" message:@"    " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

    // Adds a username Field
    alertEmailtextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 29.0)]; 
    alertEmailtextfield.layer.cornerRadius = 07.0f;
    [alertEmailtextfield setBorderStyle:UITextBorderStyleRoundedRect];
    alertEmailtextfield.placeholder = @"Enter Email";
    [alertEmailtextfield setBackgroundColor:[UIColor whiteColor]]; 
    alertEmailtextfield.autocapitalizationType =UITextAutocapitalizationTypeNone; //For Making Caps Off
    [alertview addSubview:alertEmailtextfield];

[alertview show];


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1) {

        if ([alertEmailtextfield.text length] != 0) {

            if (![self validEmail:alertEmailtextfield.text]) {

                [AlertView UIAlertView:@"Enter email is not correct"];

            }else{
                //[alertEmailtextfield resignFirstResponder];

                [NSThread detachNewThreadSelector:@selector(startSpinner) toTarget:self withObject:nil];

                Boolean isForgotPassword = [serverConnection forgotPassword:alertEmailtextfield.text];

                if (isForgotPassword) {

                    NSLog(@"Mail is send");

                    [AlertView UIAlertView:@"New password is send to your mail"];
                    [spinner stopAnimating];

                }else{

                    [AlertView UIAlertView:@"User does not exist"];
                    [spinner stopAnimating];
                }
            }
        }else{

            [AlertView UIAlertView:@"Text Field should not be empty"];
        }
    }
}

如果有人知道如何在 UIAlertView 的 UITextField 中返回键盘,请帮助我。

【问题讨论】:

    标签: iphone uitextfield uialertview


    【解决方案1】:

    您的用户界面卡在等待您的网络服务完成。在后台线程中调用您的网络服务,您的问题将得到解决。

    [self performSelectorInbackgroundThread:@selector(yourWebservice)];
    

    【讨论】:

    • 你能告诉我如何在.h中声明这个方法吗?请帮助我。
    • 当我编写此方法时,它会给出错误,例如消息未声明带有选择器“performSelectorInbackgroundThread”的方法。如果知道请告诉我如何解决这个问题。
    • @python。我给你的只是一个提示。这不是确切的语法。确切的签名是 [self performSelectorInBackground:@selector(yourWebservice) withObject:nil];。它在 NSThread.h 中可用
    【解决方案2】:

    可能是您在同一个主线程中同时执行这两项任务(Web 服务调用和键盘处理),所以在您的数据未从服务器键盘加载之前不会退出视图。在后台线程中调用 weservice 方法。

    -(void)alertView:(CustomAlert *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    [textField resignFirstResponder];
    更新
    [self performSelectorInBackground:@selector(yourWebservice) withObject:nil];

    }

    【讨论】:

    • 当我编写此方法时,它会给出错误,例如消息未声明带有选择器“performSelectorInbackgroundThread”的方法。如果知道请告诉我如何解决这个问题。
    • 是的,当然你是对的。现在我更新我的答案,请检查并尽快回复
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    相关资源
    最近更新 更多