2015-07-22 49 views
0

我想辭職鍵盤,而在背景自來水只是還是熬不過在點擊背景時不能辭職鍵盤?

首先我必須點擊編輯文本框和開放的鍵盤,我已cliked另一個文本框不可編輯後,我已經cliked背景,但我水溼辭職鍵盤

這裏是我的代碼

-(void)textFieldDidBeginEditing:(UITextField *)textField 
{ 

    if(textField == insertcity) 
    { 
     [self.view endEditing:YES]; 
     citytable.hidden = NO; 
     hoteltable.hidden = YES; 
     [self SetDynamicHieghtofTbl:citytable andArr:cityarray]; 
    } 

    if(textField == inserthotel) 
    { 
     [self.view endEditing:YES]; 
     hoteltable.hidden = NO; 
     citytable.hidden = YES; 
     [self SetDynamicHieghtofTbl:hoteltable andArr:hotelarray]; 
    } 

    if(self.txt_validationCode.tag == 3) 
    { 
     //[self.view endEditing:NO]; 
    } 

} 

-(void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 

    if(textField.tag == 3) 
    { 
     self.enteredCode = textField.text; 
    } 
} 

- (void) backgroundTap: (UITapGestureRecognizer *)recognizer 
{ 
    citytable.hidden = YES; 
    hoteltable.hidden = YES; 
    [self.txt_validationCode resignFirstResponder]; 
} 

回答

0

我希望它幫你。

- (void) backgroundTap: (UITapGestureRecognizer *)recognizer 
    { 
    [self.view endEditing:YES]; // add this line in your code 
    citytable.hidden = YES; 
    hoteltable.hidden = YES; 
    [self.txt_validationCode resignFirstResponder]; 
    } 
+0

它不起作用 –

+0

請解釋你的代碼,不要只是發佈代碼,希望他們知道這意味着什麼。 – Popeye

2

簡單的方式是到的UITextField的代表連接到自(self.mytestField.delegate =自我)和textFieldShouldReturn使用在該方法中取消鍵盤[文本字段resignFirstResponder];

另一種方式來消除鍵盤如下:

[self.view endEditing:YES]; 

[self.view endEditing:YES]; 

,你想消除鍵盤(鍵事件,觸摸事件等)。