sapanda sapanda - 3 months ago 14
iOS Question

iOS 7: Keyboard not showing after leaving modal ViewController

I've got a

HomeViewController
that has different modal segues to several other
UIViewControllers
. If I try to show the keyboard on a
UITextField
within the HomeView, everything works fine. However, if I try to show the keyboard on a
UITextField
(using
becomeFirstResponder
) after returning from any of the modal View Controllers, the keyboard never shows.

Here's some sample code from one of the setups I've tried:

In
HomeViewController
:

- (void)viewDidAppear:(BOOL)animated
{
static BOOL firstTimeComplete = false;
if (!firstTimeComplete) {
firstTimeComplete = true;
} else {
UITextField *textField = [[UITextField alloc] init];
[self.view addSubview:textField];
[textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:3]
}
}


In
ModalViewController
:

- (IBAction)done:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}


Where
done:
is linked to the "Done" button via a touch up inside event.

A few things I've tried:


  • Converting the modal segues to push segues fixes the issue, but I don't want a Nav bar in any of the child views

  • I've tried disabling and enabling animations when dismissing the
    modal view controller (using
    dismissViewControllerAnimated:
    )

  • Using unwind segues in the storyboard rather than doing it programmatically



Anyone have an idea of what may be going on?

Answer

After deleting tons of code, I finally found out that a custom NavigationController was being used and this was the root cause:

@implementation MSLNavigationController

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

@end

The app doesn't need this code, so I've nuked the file. (But an explanation as to why this would be hiding the keyboard would be awesome :))

Comments