Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView in custom inputaccessoryView not resigning first responder status

Tags:

ios

swift

iphone

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 UITextFields 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.

like image 694
blau Avatar asked Dec 18 '17 10:12

blau


2 Answers

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.
like image 107
user1046037 Avatar answered Nov 15 '22 04:11

user1046037


This warning is also shown when using the iOS message app and whatsApp. There is no known way to get rid of that. It has no negative impact, I believe we should just ignore it.

like image 22
Rémi M Avatar answered Nov 15 '22 03:11

Rémi M