0

我有一个 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 中返回键盘,请帮助我。

4

2 回答 2

1

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

[self performSelectorInbackgroundThread:@selector(yourWebservice)];
于 2012-06-07T13:14:06.037 回答
0

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

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

}

于 2012-06-07T13:30:02.663 回答