【发布时间】:2017-06-09 17:36:09
【问题描述】:
我知道已经有很多类似的问题,但是在查看了其中许多之后,它们涉及 UITextField,因此涉及 UITextFieldDelegate 的 textFieldShouldReturn 方法。 但是我有一个 UITextView,而不是 UITextField,我想知道用户何时点击了相关键盘上的完成按钮。
我有一个表格视图,当用户点击其中一行时,表格进入编辑模式,用户可以在单元格内的 UITextView 中输入文本。这是一些代码:
包含文本视图的单元格
class ReportTextEntryCell : UITableViewCell
{
@IBOutlet weak var commentsTextView: UITextView!
}
单元格的创建,在 cellForRowAt 中调用
func getTextEntryCell() -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "TextEntryCellID") as? ReportTextEntryCell
cell!.commentsTextView.delegate = self
cell!.commentsTextView.keyboardAppearance = .light
cell!.commentsTextView.keyboardType = UIKeyboardType.default
cell!.commentsTextView.tintColor = UIColor.black
cell!.commentsTextView.returnKeyType = .done
return cell!
}
键盘出现,用户可以输入文字。
表格视图控制器实现UITextViewDelegate 和textViewShouldBeginEditing 和shouldChangeTextIn 都被调用。
但我原以为textViewShouldEndEditing 会在用户点击键盘上的“完成”按钮时被调用,但事实并非如此。
我如何知道用户何时点击了完成按钮?
【问题讨论】: