UITextView in custom inputaccessoryView not resigning first responder status

I have a chat application that implements a floating text input field (similar to the iOS Messages app) as the inputAccessoryView of my ChatViewController (see Apple's documentation).

class ChatViewController: UIViewController {

    override var inputAccessoryView: UIView? {
       return chatInputView
    }

    override var canBecomeFirstResponder: Bool {
        return true
    }
    ...

My ChatViewController has a ChatTableViewController child view controller, which has cells containing UITextField s whose text content is editable. The issue I'm running into is that when the user taps on a cell's UITextField , the inputAccessoryView 's UITextView refuses to resign first responder status, which prevents the content in the UITableViewCell from being edited. The following warning is logged in the console:

 First responder warning: '<UITextView: 0x7fc041041c00; 
 frame = ...' rejected resignFirstResponder when being removed from hierarchy

I've tried calling resignFirstResponder and endEditing on the UIInputView and UITextView directly with no success. I don't want the ChatViewController to resign first responder status as that would cause the inputAccessoryView to disappear.

Edit: I also receive the warning when dismissing the keyboard interactively (instead of tapping on the UITableViewCell 's UITextField .


Could you please check the following:

If UITextView is removed from super view:

  • Is the UITextView being removed from the view hierarchy ?
  • If so could you resignFirstResponder before removing it from the super view.
  • If UITextView subclass is being used:

  • Are you using a subclass of UITextView , if so have you implemented canResignFirstResponder to return false .
  • Could you try returning true instead.
  • 链接地址: http://www.djcxy.com/p/7708.html

    上一篇: 用Maven执行Ant任务

    下一篇: 自定义inputaccessoryView中的UITextView不会退出第一响应者状态