2012-03-20 49 views
2

我在我的視圖中有兩個文本字段。我使用IB做了它。在第二個文本字段中我使用的操作工作表如何使其他文本字段的鍵盤在訪問其他文本字段時消失

在textField1中輸入文本後我在文本字段2-2中。第二個文本字段中我使用操作表與選擇器來選擇日期。所以我在打開操作表之前辭職了textfield -2鍵盤。當我試圖辭職鍵盤時,我解僱了行動表後並沒有回來。 我用

- (BOOL)textFieldShouldReturn:(UITextField *)textField{ 
    [textfield1 resignFirstResponder]; 
    return YES; 
} 

辭職textfield1的..

回答

4
- (void) viewDidLoad 
{ 
    //don't forget to add <UITextFieldDelegate> in your .h 
    firstTextField.delegate=self; 
    secondTextField.delegate=self; 
} 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    if(textField.tag==2) 
    { 
     //Here you can call function to view your datepicker 
     return NO; //Will not open keyboard for second textfield. 
    } 
    return YES; 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    [textField resignFirstResponder]; 
    return YES; 
} 
0

你必須返回當前文本框textFieldShouldReturn方法改變你的textFieldShouldReturn梅託德像下面

- (BOOL)textFieldShouldReturn:(UITextField *)textField{ 
    [textField resignFirstResponder]; 
    return YES; 
} 
0

設置標籤的每一個文本字段,並檢查它們在

-(BOOL)textFieldShouldReturn:(UITextField *)textField 
{ 
    if([textfield.tag == 1]) 
    { 
     [textFieldFirst resignFirstResponder]; 
    } 
    else 
    { 
    // your action sheet code here 
    } 
    return YES; 
} 
0

您需要提供返回的第一個標籤的文本字段,

在這個方法中,

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{    
    if (textField.tag == 2) 
    { 
     [textField1 resignFirstResponder]; 
     // your action sheet code here 
    } 
} 

- (BOOL)textFieldShouldReturn:(UITextField *)textField   
{ 
    [textfield resignFirstResponder] 
    return YES; 
} 
+0

我試圖爲u說,但它簡化版,工作........... – vamsi575kg 2012-03-20 11:22:27

+0

有出文本字段鍵盤我傳遞到第二個。第二字段的文本字段沒有打開,因爲我辭去了第一響應者..但是第一字段的鍵盤沒有退出@ – vamsi575kg 2012-03-20 11:25:51

相關問題