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

2019-01-07 16:23发布

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

7条回答
劳资没心,怎么记你
2楼-- · 2019-01-07 16:53

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

查看更多
Rolldiameter
3楼-- · 2019-01-07 16:57

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.

查看更多
beautiful°
4楼-- · 2019-01-07 16:59

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

查看更多
劫难
5楼-- · 2019-01-07 17:05

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.

查看更多
唯我独甜
6楼-- · 2019-01-07 17:10

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

查看更多
姐就是有狂的资本
7楼-- · 2019-01-07 17:13

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!

查看更多
登录 后发表回答