下面的方法使用返回鍵來關閉UITextView鍵盤。
在你的控制器中,UITextView中的委託設置爲自 這樣的:如果你不使用回車鍵爲
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
// Any new character added is passed in as the "text" parameter
if ([text isEqualToString:@"\n"]) {
// Be sure to test for equality using the "isEqualToString" message
[textView resignFirstResponder];
// Return FALSE so that the final '\n' character doesn't get added
return FALSE;
}
// For any other character return TRUE so that the text gets added to the view
return TRUE;
}
這應該工作:
myTextView.delegate=self;
然後添加此方法一個真正的回車鍵(例如添加新行)。
是不是UITextView支持多行的整個想法?否則,爲什麼不使用UITextField? – PaulG 2012-12-13 15:45:24