Can't type text into UITextField or UITextView

2019-04-18 03:36发布

问题:

In one of my apps, when I try to edit (type some text) UITextField, UITextView or any other 'text-able' UIControl the cursor just blinks but no characters are typed in except BACKSPACE (possible only when I have some initial text in it), RETURN and switching character types. This goes to all controls across whole application.

Summary:

  1. It happens only from iOS 6.0 (does not occur on iOS 5.x, 4.x neither Simulator or real device)
  2. All delegate methods are fired (shouldBeginEditing: didBeginEditing:) except shouldChangeCharactersInRange:
  3. isFirstResponder flag is behaving set correctly (shouldBeginEditing: logs NO, while didBeginEditing: logs YES correctly). It is also tested using logs that THE firstResponder IS the one already edited.
  4. It repairs itself after any UIAlertView is presented to the user and dismissed. It doesn't matter if this alert is shown on the same screen (UIViewController view) or any other.

I have no idea how to even approach or debug this.

Where should I look for hints? Any experts of tracking responder chain related issues etc.?

How can I track down the UIAlertView's effect on the issue?

回答1:

Depending on your implementation it's either the makeKeyAndVisible method of the UIWindow class that you forgot to call inside the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method of the application delegate or corresponding Visible at Launch flag in your main interface xib file.

Cheers... :)



回答2:

in my case, there is a 'visible at launch' on the main window, it was unchecked, which works on iOS5 only, needs to check it to make it working on iOS6.



回答3:

In my situation I had an activity indicator that would pop up over the main window during periods of background activity. In this case the activity indicator view had its own window that was set to UIWindowLevelAlert. I was inadvertently calling makeKeyAndVisible on this window. Later on I would call resignKeyWindow. This used to work on iOS 4 and 5 but no longer worked in iOS 6. I discovered that this was not technically necessary as simply using window.hidden = Y/N worked just as well.



回答4:

In my case I moved becomeFirstResponder for my UITextField from ViewDidLoad to ViewDidAppear and this solved my problem.