0

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?

Thanks a lot for your advice!

6
  • Please consider post some code along with the crash log. Sep 26, 2013 at 20:00
  • 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?
    – YuliaSh.
    Sep 26, 2013 at 20:01
  • mm, did set navigation controller delegate? Sep 26, 2013 at 20:04
  • 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.
    – YuliaSh.
    Sep 26, 2013 at 20:18
  • 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.
    – YuliaSh.
    Sep 26, 2013 at 20:29

2 Answers 2

0

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 here.

3
  • 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.
    Sep 27, 2013 at 11:18
  • Try to out [textView resignFirstResponder]; in your viewWillDisapear, if nothing happened, please edit your question and post your code. Sep 27, 2013 at 12:52
  • Unfortunately, it did not help. But I've found out a solution! I will answer my question. Thanks a lot for your advice.
    – YuliaSh.
    Sep 27, 2013 at 14:03
0

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: and 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.