Keyboard and cursor show, but I can't type ins

2019-01-07 16:28发布

问题:

On an iPad with iOS 6 GM. I have 6 UITextFields, 3 UITextViews, and a UIButton that triggers a popover/actionsheet.

When I select one of the UITextFields or UITextViews, the keyboard pops up and the cursor appears, but I can't enter text. If I press the UIButton to show the popover and then tap outside it to dismiss it and go back to the UITextFields or UITextViews, they work.

I have UITextxxxx.delegate = self; set for all of them. "Enabled" and "User Interaction Enabled" checked off in the xibs, UITextFieldDelegate and UITextViewDelegate in my .h file as well as:

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    return YES;

}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {

    return YES;

}

- (IBAction)textFieldReturn:(id)sender {

    [sender resignFirstResponder];
}



- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {

    if (textView == notestextView){
        [notestextView becomeFirstResponder];
    }
    if (textView == notestextViewTwo){
        [notestextViewTwo becomeFirstResponder];
    }
    if (textView == notestextViewThree){
        [notestextViewThree becomeFirstResponder];
    }

    return YES;

}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView {

    return YES;

}

I even tried to [xxxxxxx becomeFirstResponder]; in viewDidLoad. That pops the keyboard and places the cursor in the field at runtime, but I still can't type in it until I tap the UIButton to show the popover.

Anyone know why I can't type in the fields and why envoking the popover "fixes it"?

UPDATE 9/18: I pushed a new view in my app that just has a view with a textfield and a textview. Delegates are all set up. Same behavior. Keyboard and cursor appear, but no typing. That rules out the popovercontroller messing with things.

I'm strongly starting to think this is an iOS 6 bug. This is pretty much the same view I had in the iPhone version of my app on iOS 4 and 5 and I never had a problem. The only difference between the iPhone and iPad version is the way the imagepicker is presented. You have to use a popover for the iPad. That’s why I was thinking that the popover delegate had something to do with it.

Is there any kind of fundamental difference between implementing UITextFields and UITextViews in iOS 6 that I don't know about? Seems unlikely.

If it helps my app flows like this:

Main View with 10 buttons

  • each button pushes a tableview via a navigation controller
  • tableviews push a detail view - textfields and textviews exhibit behavior described above
  • tableview also has an add button that pushes a modal view to add new items - textfields and textviews exhibit behavior described above

回答1:

This was originally an iPhone app built on iOS 5. To make it an iPad app, I just duplicated the project and upgraded all the .xibs to iPad versions. I don't know if it's a bug or not, or if it's something to do with the upgrade to iOS 6, but doing it like that messes something up with the MainWindow.xib.

In the MainWindow xib, I typed in "MainViewController" for the title (It was previously blank.)

And checked off "Visible at Launch". Even though it is already visible at launch, not having that checked off screws something up.

Now all my text views and text fields work.



回答2:

I ran into this same issue, make sure that the app delegate has a [self.window makeKeyAndVisible]. That solved it for me.



回答3:

For me your solution doesn't work so I found another.

I'm using Revmob Ads so fullscreen view and banner view are loading when app is launched. Revmob uses some staff for displaying same banner in all viewcontrollers I think here is issue. When I disabled revmob I can add text to my textfield.



回答4:

This is apparently bug in iOS 6. Just put [searchBar becomeFirstResponder]; into searchBarTextDidBeginEditing method:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    if (!self.window.isKeyWindow) {
        [self.window makeKeyAndVisible];
    }
}

This solution works for me.



回答5:

These solutions didn't work for me, but after I deleted the derived data folder at ~/Library/Developer/Xcode/DerivedData/AppName, it worked.



回答6:

To clarify other answers, you can not input text to a window that is not set to be the key window. Most applications only use one window, or don't have text input on additional windows so never encounter this problem.

When handling multiple windows make sure to resignKeyWindow+makeKeyWindow while switching the focus and, very important, to restore the key window afterwards!



回答7:

Try becomeFirstResponder in dispatch_async(dispatch_get_main_queue(),^{});