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

It should be simple, but it becomes a headache. I have a view with UITextField where a user types and clicks text. In this case, another view controller appears, and I leave the first responder in the text box before the first view disappears. When the second view is rejected, the first view automatically causes the text field to become the first responder again, and I cannot find a way to suppress it. Does anyone know how I can make the keyboard pop up when I deflect a second look?

I tried resignFirstResponder in viewWillAppear, no effect. I tried the same thing in viewDidAppear, but the keyboard pops up and then fires immediately, which is inconvenient.

I appreciate any help.

+7
source share
1 answer

I found a fix, but it is not very good.

It is established that the canBecomeResponder message is sent to the text field immediately after viewWillAppear and before viewDidAppear .

So, I set the BOOL value to viewDidAppear in YES and used this value in the textField:shouldBeginEditing . Basically, if viewDidAppear has not yet been called, textField:shouldBeginEditing returned NO.

+5
source

All Articles