2012-06-07 23 views
0

我有一个UIAlertView包含一个UITextField与确定和取消按钮。当我点击确定按钮时,我打电话给webService。我想在调用webservice之前返回键盘。键盘不会返回,直到响应不是来自webservice。由于在加载webservice期间用户看不到这半屏幕。这是我做的代码。如何在iphone的UIAlertview中为UITextField返回键盘?

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

+0

表现出一定的代码? –

回答

0

可能是ü正在做同样的主线任务都(Web服务调用和键盘resinging),所以直到乌尔数据是无法从服务器加载键盘没有从视图辞职。在后台线程中调用weservice方法。

- (无效)alertView:(CustomAlert *)alertView clickedButtonAtIndex:(NSInteger的)buttonIndex {
[文本字段resignFirstResponder];
更新
[self performSelectorInBackground:@selector(yourWebservice)withObject:nil];

}

+0

当我写这个方法时,它给出的错误如实例消息没有声明一个带有选择器'performSelectorInbackgroundThread'的方法。如果知道请告诉我如何解决这个问题。 – python

+0

是的,当然你是对的。现在我更新我的答案,请检查并尽快回复 – kulss

1

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

[self performSelectorInbackgroundThread:@selector(yourWebservice)]; 
+0

你能告诉我如何在.h中声明这个方法吗?请帮助我。 – python

+0

当我在写这个方法时,它给出的错误就像实例消息一样,没有声明一个带有选择器'performSelectorInbackgroundThread'的方法。如果知道请告诉我如何解决这个问题。 – python

+0

@python。我给你的只是一个提示。这不是确切的语法。确切的签名是[self performSelectorInBackground:@selector(yourWebservice)withObject:nil] ;.它在NSThread.h中可用。 – Vignesh

相关问题