19

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
Community
  • 1
  • 1
RyeMAC3
  • 1,023
  • 1
  • 10
  • 17

7 Answers7

37

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.)

enter image description here

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

enter image description here

Now all my text views and text fields work.

elitalon
  • 9,191
  • 10
  • 50
  • 86
RyeMAC3
  • 1,023
  • 1
  • 10
  • 17
  • i am also having same problem and trying to solve it as u done but its not working.. – Anju Oct 01 '12 at 10:06
  • 3
    How can I do this without NIB ? – Borut Tomazin Jan 04 '13 at 09:58
  • I'm having a similar problem with multiple UIAlerts and eventually when the main view returned focus the Windows was not the key window. Using @BorutTomazin's [answer](http://stackoverflow.com/a/14155012/34155) I was able to fix it. Instead of doing it on the search bar, just do it during EditingDidBegin of the UITextField – Jonas Stawski Mar 11 '13 at 17:29
12

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

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
  • 1
    @AndrewCarter I had [self.window makeKeyAndVisible] in my AppDelegate, but it didn't work. ReyMAC3's solution worked... so they can't be the same. – Marco Nov 02 '12 at 16:00
  • 1
    Thanks!, Just to make it more clear, [window makeKeyAndVisible] should be placed in didFinishLaunchingWithOptions – DeZigny Dec 10 '12 at 21:11
  • Update: It worked for couple of days, then the same problem is showing again :/ – DeZigny Dec 19 '12 at 09:40
2

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.

Danil
  • 1,780
  • 17
  • 24
  • So your app functions normally and had nothing to do with MainWindow or the delegate implementation? Of course my solution won't work for an incorrectly implemented Revmob ad. – RyeMAC3 Sep 25 '12 at 17:43
  • 2
    @RyeMAC3 I wrote that because I thought that my answer can help another people. By the way Revmob can't fix this bug for now. Here is workaround: `RevMobAds *revmob = [RevMobAds revMobAds]; RevMobBannerView *bannerView = [revmob bannerView]; [bannerView loadAd]; bannerView.frame = CGRectMake(0, 0, 320, 50); [view addSubview:bannerView];` – Danil Oct 02 '12 at 03:59
  • Yeah I had the same problem. I didn't even notice it as I didn't even put Revmob on the page that had a problem. Just having it in the app screwed them up. I hit pause online and they work again. I had another app that they stopped images from being swapped. No idea what they are doing, but I won't be putting them in any more apps. No way an ad on a different screen should be affecting my app. – clarky Nov 18 '12 at 15:22
2

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.

Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91
  • I'm not entirely sure why but this worked for me. I have a login view controller where if the user typed in the wrong credentials, the second time they came back to re-input their credentials the text fields would receive focus but you couldn't type. After adding the above code to my textFieldDidBeginEditing: method it started working! – Brian Moncur Aug 15 '13 at 17:02
0

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

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
0

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!

Rivera
  • 10,792
  • 3
  • 58
  • 102
0

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

NovemberEleven
  • 245
  • 3
  • 10