2012-06-07 29 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

相關問題