Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the warning that appears about resignFirstResponder when using interactive keyboard?

This is only a warning and the app works fine but there might be a reason for this warning to be there.

I found similar issues on the web but no answers yet. first, the error:

[View] First responder warning: '; layer = ; contentOffset: {0, 0}; contentSize: {302, 20}; adjustedContentInset: {0, 0, 0, 0}>' rejected resignFirstResponder when being removed from hierarchy

The setup is a chatviewcontroller so it's a UITableView embedded inside a UIViewController that contains cells with text.

We are using the Dismiss Interactively keyboard function of the UIScrollView class to be able to dismiss the keyboard when we swipe down on the list of chat items.

We add an inputAccessory to the keyboard to be used as a text input area + send button.

In the UIViewController that contains the UITableView, we add the following UIResponder override to get the accessoryView.

override var inputAccessoryView: UIView {
    return messageInputView
  }

The problem is that we dismiss interactively the keyboard (so that it disappear from the screen), we get this warning. Any input, any help on the topic would be great!

like image 881
Mikael Avatar asked Jan 26 '18 09:01

Mikael


People also ask

Which method can be used to dismiss the system keyboard if a UITextField or Uitextview is currently being edited?

You can ask the system to dismiss the keyboard by calling the resignFirstResponder method of your text field. Usually, you dismiss the keyboard in response to specific interactions. For example, you might dismiss the keyboard when the user taps the keyboard's return key.

Which delegate function removes keyboard in UITextField?

If you have a UITextField and you want to hide the keyboard when the user is pressing the return key, use the textFieldShouldReturn function. Be sure you have set the textField. delegate = self in your viewDidLoad() function.

How do I resign from first responder?

If you want that text control to stop waiting for input – which in turn dismisses the keyboard – you should call its resignFirstResponder() method, which passes the first responder baton to the next waiting component.


1 Answers

I just found out that if you override the viewWillTransition function and call collectionView.collectionViewLayout.invalidateLayout() in it, it will fix the problem!

like image 190
Sotiris Kaniras Avatar answered Oct 12 '22 01:10

Sotiris Kaniras