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