Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField becomes first responder when view becomes visible, but I don't want it to

This should be simple, but it's becoming a headache. I have a view with a UITextField where the user types some text and clicks search. This pops up another view controller, and I resign first responder on the text field before the first view disappears. When the second view gets dismissed, the first view automatically makes the text field become first responder again and I can't find a way to suppress this. Does anyone have any idea how I can keep the keyboard from popping up when I dismiss the second view?

I tried to resignFirstResponder in viewWillAppear, no effect. I tried the same in viewDidAppear, but the keyboard pops up and then immediately dismisses which is awkward looking.

I appreciate any help.

like image 574
SeanT Avatar asked Jun 21 '13 22:06

SeanT


1 Answers

I found a fix, but its not a very good one.

Found that canBecomeResponder message was being passed to the textfield right after viewWillAppear and before viewDidAppear.

So I set a BOOL value in viewDidAppear to YES, and used that value in textField:shouldBeginEditing method. Basically if the viewDidAppear was not called yet, textField:shouldBeginEditing was returning NO.

like image 159
Adithya Avatar answered Oct 10 '22 06:10

Adithya