简体   繁体   中英

Keyboard not hiding in iOS 6

I'm pushing a view controller to a navigation controller and in iOS 7 when that happens the keyboard automatically hides.

However, in iOS 6, it does not. I also can't get it to go away with [self.view endEditing:YES]; .

EDIT: In the preceding view controller, once the keyboard is brought up, it does not go away in that view controller with [self.view endEditing:YES] either.

You could try this:

-(void)viewWillDisappear:(BOOL)animated{

    [self performSelector:@selector(resignFirstResponder) onChildrenOfView:self.view];

}

-(void)performSelector:(SEL)selector onChildrenOfView:(UIView*)view{

    for ( UIView * subView in view.subviews ) {

        if ( [subView respondsToSelector:selector] ) {
            [subView performSelector:selector];
        }

        if ( [subView isKindOfClass:[UIView class]] ) {
            [self performSelector:selector onChildrenOfView:subView];
        }

    }

}

Sorry if it's a little verbose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM