Search code examples
iphoneobjective-ccocoa-touchuitextfielduitextfielddelegate

Modal View Issue


I have an issue with some of my views, here is a breif outline of my setup:

Tab Bar Controller
|
--View Controller 1
|
--View Controller 2
|
--View Controller 2

On a certain action, View Controller 1 will display a modal dialogue. Within this dialogue, if the user performs another action, then another modal dialogue is shown, using the first modal dialogue to present the view.

On the 2nd ModalDialog I have a UITextField, however when I attempt to type into the text field, nothing happens. Even though the keyboard is displayed and the textFieldDidBeginEditing method is called. I have setup the UITextFieldDelegate and the nessessary responders, but to no avail.

Does anyone know what would cause this issue?

Many Thanks


Solution

  • I've found that on a number of occasions with changing views and with popovers that text fields haven't focused correctly with symptoms like you describe. On these occasions I end up deferring the becomeFirstResponder call until the animation has finished or the view has loaded - for example in a view controllers viewDidAppear method.

    Or, simply delay the call to becomeFirstResponder with an appropriate guestimate of the time it will take for the views to change / animate / etc. ie:

    [textField performSelector:@selector(becomeFirstResponder)
                    withObject:nil
                    afterDelay:0.3];