문제

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

도움이 되었습니까?

해결책

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];

다른 팁

I would try to 'chain' the modal dialogs from the view controller if that's possible.

  • The VC opens the 1st modal dialog
  • Your 1st modal dialog notifies the VC (using delegation probably).
  • (Maybe required) Close the 1st modal dialog
  • The VC opens the 2nd modal dialog
  • Happiness!

I'm not sure what you mean with "modal dialogue" -- I assume you mean either a modally presented view controller with a UIModalPresentationFormSheet modal presentation style or a UIPopoverController.

Here's my best guess: I'm pretty sure that your "modal dialogue" captures all user interactions (by default). So when pushing the first one, it captures all input focus. When pushing the second one, it's capture conflicts with the previous one and hence the keyboard will not work.

Anyways, both types of "modal dialogues" are not meant to be stacked. Even if it may work technically, I dislike like it form a interaction-design perspective. Instead of trying to fix the bug or work around it, try to rethink you modal dialogue. You may fit everything into a single one. For example by using a navigation controller inside that view, or by replacing the the view or by flipping it's contents... etc.

Hope this helps, Max

If I were you I would consider revising the navigational hierarchy. Modal dialogs are considered bad enough as it is, but incorporating a modal dialog within a modal dialog is user interface suicide. It causes confusion to the user and is very non-traditional. Is there any way you can use the first modal popup and simply exchange the content?

A side note: You mentioned setting up the view as being a UITextViewDelegate. Did you the view as the delegate for the textbox? Are you returning NO or FALSE from - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top