ios8keyboardpopviewcontroller

iOS8 : When Keyboard appear and press Back button, at that time next view appear very slow


I have ViewController (v2) with the UITextView . I pushed that view from the viewController (V1). On V2 When I tap on textview and keyboard appear after that tap on back button and move on V1. I repeat this process 15 to 20 time and notice that my app's performance become very slow.

Issue is Keyboard take long time to disappear when I tap on Back button :

I am using following line of code :

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

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];

}

- (IBAction)back:(id)sender
{
    [self.navigationController popViewControllerAnimated:NO];
}

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

- (void)viewWillDisappear:(BOOL)animated {

    [noteView resignFirstResponder];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];

    [super viewWillDisappear:animated];
 }

- (void)willShowKeyboard:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}

- (void)keyboardDidHide:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}

Solution

  • It is simple one line code to dismiss keyboard when user press back button

    - (IBAction)back:(id)sender
    {
        [self.view endEditing:YES];
        [self.navigationController popViewControllerAnimated:NO];
    }