Search code examples
iosios7keyboardsegueautorotate

iOS 7: Keyboard not showing when using Modal segue & autorotate == NO


(This an extension of iOS 7: Keyboard not showing after leaving modal ViewController)

I've got a HomeViewController that uses a NavigationController. Clicking a button takes you to ModalViewController using a modal segue. Pressing the back button then takes you back to the HomeViewController, which then pops up a keyboard. The weird part though is that the keyboard never shows up. I've verified that the UIKeyboardDidShowNotification does get fired , UIKeyboardDidHideNotification doesn't and [textfield isFirstResponder] returns true. Which means the keyboard should be shown right??

I've verified that this only occurs if I have a modal segue, and the NavigationController::shouldAutorotate returns NO.

I've copied the relevant code below. Any help would be greatly appreciated!!

NavigationController.m:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

HomeViewController.m:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if (firstTimeComplete) {
        UITextField *textField = [[UITextField alloc] init];
        [self.view addSubview:textField];
        [textField performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:3];
    }
}

ModalViewController.m:

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

Solution

  • Fixed! The problem was because I was using UIInterfaceOrientationPortrait instead of UIInterfaceOrientationMaskPortrait. I think masks are the expected type for supportedInterfaceOrientations