La barra de navegación de ios7 provoca EXC_BAD_ACCESS después de descartar el VC con el teclado mostrado

I have a Notes-like app: UITableViewController showing up individual notes by pushing them onto navigation stack.

The problem arises when I have UITextView with the FirstResponder status (keyboard is shown) and I touch Back button. The current view controller is dismissed with the animation as expected, BUT the navigation bar is broken now! If I press any of the bar buttons, it will cause EXC_BAD_ACCESS.

I would say that it was not transitioned properly. The table VC is broken somehow as well, as it may appear empty on further manipulations... Very strange behaviour!

By the way, it did not cause any problems with iOS5 and iOS6, but there I used a custom chevron Back button.

I've checked the standard Notes app and it works like a charm. What is the trick?

¡Muchas gracias por tu consejo!

preguntado el 26 de septiembre de 13 a las 20:09

Please consider post some code along with the crash log. -

After some tracing, I've found out that UITableViewController's viewWillAppear: and viewDidAppear: methods are not triggered after going Back to it with an active keyboard. Why could it be? -

mm, did set navigation controller delegate? -

No, should I set it? What for? The issue is seen only with the keyboard active, if I dismiss it before going Back in navigation, everything is just fine. -

I have one quess... I am calling [self.navigationController popViewControllerAnimated:YES]; in textViewDidEndEditing: if no text was added into the view. And it might overlap with ongoing popViewController-animation triggered by Back button. -

2 Respuestas

EXC_BAD_ACCESS means you are trying to access an object that has been deallocated. Best thing you can do to trace this is enabling NSZombie, it will tell you what released object is being sent a message (aka EXC_BAD_ACCESS).

You can get how to enable it from aquí.

contestado el 23 de mayo de 17 a las 12:05

I understand why EXC_BAD_ACCESS is raised and what causes it, as I said earlier in the comment. popViewControllerAnimated: is called twice (from Back button by the system and from textViewDidEndEditing:). I just do not know how to handle it properly, how to check if the back-button animation is already in progress... - YuliaSh.

Try to out [textView resignFirstResponder]; in your viewWillDisapear, if nothing happened, please edit your question and post your code. - Tarek Hallak

Unfortunately, it did not help. But I've found out a solution! I will answer my question. Thanks a lot for your advice. - YuliaSh.

I got it and will try to explain to help somebody else to save their day...

EXC_BAD_ACCESS was raised because UITableViewController was not properly transitioned to during Back pop-animation (its viewWillAppear: y viewDidAppear: method were not triggered at all). In its turn, the animation was not properly performed, as popViewControllerAnimated: was called twice or even more times: 1) as part of the system Back-button callback; 2) inside textViewDidEndEditing: in case no text was entered.

The solution is to check whether the back button has been pressed before calling popViewControllerAnimated:. The trick is to check if the detail-view controller is still in the navigation stack. Here is the helper method:

-(void) returnToTheListOfRecords {
    self.textView.delegate = nil; // this is to avoid the second call of `textViewDidEndEditing:`
    if ([self.navigationController.viewControllers indexOfObject:self.delegate]==NSNotFound) {
        // Back button has been pressed.
    } else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

The problem happens on iOS7 only due to its brand-new animation.

Respondido el 27 de Septiembre de 13 a las 15:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.