如何从UITableview for Uad中定义的UITextview中解除键盘

时间:2012-10-19 05:40:50

标签: ipad

我是iPad编程的新手,我想知道如何从UItablecell中定义的UItextview中解除键盘。我在单元格中定义了多个textview。请帮助我找到你身边的正确解决方案或建议。

1 个答案:

答案 0 :(得分:1)

向文本视图发送消息resignFirstResponder,键盘将解除。如果您需要将其关闭以响应返回键,请查看视图控制器是否采用UITextViewDelegate协议。

[self.textViewInQuestion resignFirstResponder];

或者,您可以将endEditing:消息发送到表格视图,如下所示:

/*
  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];