UIKit sets first responder to nil, making it impossible to send -undo: (and other actions) to appropriate targets

In our applications, we have an Undo button in our main view controller’s navigation bar. This button is supposed to do two things:

  • If there is a text field being edited, it should undo in the text field’s undo stack.

  • Otherwise, it should undo in the document’s undo stack.

Unfortunately, dismissing the keyboard clears out the window’s first responder, which means the -undo: message never makes it to the view controller.

[Read more…]