3

我是 iPad 编程的新手,我想知道如何从 UItablecell 中定义的 UItextview 关闭键盘。我在单元格中定义了多个文本视图。请帮助我提供适当的解决方案或建议。

4

1 回答 1

1

Send the text view the message resignFirstResponder and the keyboard will dismiss. If you need to have it dismiss in response to the return key, look at having your view controller adopt the UITextViewDelegate protocol.

[self.textViewInQuestion resignFirstResponder];

Alternatively, you can send the endEditing: message to the table view like this:

/*
  Attempt to resign first responder status on any textfields within 
  the view's hierarchy.
*/

[self.tableView endEditing:NO];


// OR we can....


/*
  Force text fields within the view's hierarchy to resign first responder.
  Textfield delegates cannot prevent this from happening so this is not 
  recommended if you need to perform field validation and prevent the user 
  from leaving the textfield.

  However sometimes it is useful to be able to force the resignation of the 
  first responder status even with validation so it goes both ways really.
*/

[self.tableView endEditing:YES];
于 2012-10-19T05:45:50.077 回答