Search code examples
iosnsnotificationsxcode10ios12swift4.2

iOS - Keyboard Notifications not firing while switching UITextfields


There is a strange behavior going on with notifications. My notifications were firing properly whenever I switch one UITextfield to another. But recently I noticed they are not being fired now while switching from one UITextField to another but firing properly when the keyboard is hidden. Has Apple changed this logic?

I need to scroll the field to visible and as the observers are not firing now while switching, the fields don't come to visible rect.

I have created an alternative by posting notification on the textFieldDidBeginEditing, but I would like old way back if it is possible.


Solution

  • I found the real reason of my issue. Keyboard notifications will not be called while switching if the UITextfield do not have accessory view and in case of accessory view they will be called each time (Why is UIKeyboardWillShowNotification called every time another TextField is selected?)

    In my case I had accessory view on each field but while adding accessory view I was adding same view to all of the fields, that was the real problem. I needed to assign separate instance of UIView to different fields. As soon as I did that my problem was gone.