2013-03-05 67 views
0

嗨,這是我的代碼我試圖讓用戶界面文本視圖鍵盤消失。我有2個文本字段,第二個是文本視圖。我嘗試拖動動作,但它不會讓我。請幫忙!!!!!我無法讓用戶界面文本視圖鍵盤消失

- (IBAction)dismiss1:(id)sender{ 

[sender resignFirstResponder]; 
} 

- (IBAction)dismiss2:(id)sender2{ 

[field2 resignFirstResponder]; 
} 

回答

0

UITextView沒有事件動作。

Import <UITableViewDelegate, UITableViewDataSource> in header file and use below code to disapear keyboard when click on return button. 

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
{ 

    if ([text isEqualToString:@"\n"]) { 

     [self.textView resignFirstResponder]; 
     // Return FALSE so that the final '\n' character doesn't get added 
     return NO; 
    } 
    // For any other character return TRUE so that the text gets added to the view 
    return YES; 
} 
+0

嘿,對不起,我是一名新開發人員,所以我把第一部分放在.h文件中,然後在.m文件中重複其他所有內容?我有field2所以我會用textView替換textView?謝謝! – 2013-03-05 11:20:47

+0

@JoeMasciantonio,是的。像這樣:interface yourheaderfilename:baseclass 2013-03-05 11:30:47

+0

對不起,我仍然有問題 – 2013-03-05 20:08:12