I need to resignFirstResponder()
on a text field when the user taps the back button in the navigation bar of the navigation controller, otherwise I get some error. The back button works as it should (the previous view gets shown) but I don't know where to do resign first responder. It's too late if I do it in viewWillDisappear()
(I tried), and prepareForSegue()
doesn't get called, so I need to somehow do it as soon as the back button gets tapped or at least before viewWillDisappear()
. How do I detect that event?
Asked
Active
Viewed 3,052 times
1

TimSim
- 3,936
- 7
- 46
- 83
-
1It question was in stackoverflow - [answer](http://stackoverflow.com/questions/8228411/detecting-when-the-back-button-is-pressed-on-a-navbar) answer – Savchenko Dmitry Jun 16 '16 at 23:18
1 Answers
2
Note: See first comment on question for simpler answer
You could combine NotificationCenter
and this post: Execute action when back bar button of UINavigationController is pressed to make a custom back button (that looks the same). Just post a Notification
in the action for the back button, and add an observer for the Notification
on the textfield
whose action calls resignFirstResponder
. You would also need to make an image or draw an image in CoreGraphics for the arrow.