Đối với UITextView
đặt textView.userInteractionEnabled = false
và nếu bạn có UITextField
, hãy đặt textField.userInteractionEnabled = false
.
Nếu bạn muốn TextView hoặc TextField được chỉnh sửa sau khi các tế bào với nó được khai thác, làm một cái gì đó như thế này:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let cell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
// find first textField inside this cell and select it
for case let textField as UITextField in cell.subviews {
textField.userInteractionEnabled = true
textField.becomeFirstResponder()
return
}
// find first textView inside this cell and select it
for case let textView as UITextView in cell.subviews {
textView.userInteractionEnabled = true
textView.becomeFirstResponder()
return
}
}
Sau đó, hãy chắc chắn để vô hiệu hóa tương tác người dùng sau khi bạn hoàn tất chỉnh sửa:
func textFieldDidEndEditing(textField: UITextField) {
textField.userInteractionEnabled = false
// rest of the function
}
func textViewDidEndEditing(textView: UITextView) {
textView.userInteractionEnabled = false
// rest of the function
}
Đừng quên để thiết lập UITextFieldDelegate
và/hoặc UITextViewDelegate
tôi hy vọng điều này giúp một ai đó :)
userInteractionEnabled = NO work. Cám ơn rất nhiều. –
TextView không có thuộc tính được bật. –