0
votes

I had two Table View Controllers and they are connected each other by "segues" in Storyboard. Then I've cut the "segues" and insert another controller. And connection now is not through "segues". To connect the views I'm using the code:

UIStoryboard *storyboard = self.storyboard;
OptionsViewController *options = [storyboard instantiateViewControllerWithIdentifier:@"OptionsViewController"]
[self.navigationController pushViewController:options animated:YES];

And now when I'm clicking a "Back" button in navigation bar my program crashes. How to fix it?

Console shows (After view loaded, before I've pressed the "Back" button.): "nested push animation can result in corrupted navigation bar" "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted."

After I've pressed the "Back" button: "terminating with uncaught exception of type NSException"

Navigation Controller is the initial controller in my storyboard, but the Views are not connected each other.

FIXED: I've just set the "animated:NO" at the end of my code.

2
What is optionsViewController ? - Bhumeshwer katre
what you get in console when your application is crash ?? any error ?? - Bhavin_m
I think your problem is that the uinavigationcontroller is getting deallocated. - Vizllx
make as your viewcontroller as retain/strong properties - codercat
You may have fixed the crash by setting animated to NO, but the fact that you get the "nested push animation can result in corrupted navigation bar" message means you're doing something wrong in your transitions -- usually that error means you're trying to do 2 transitions at once. - rdelmar

2 Answers

0
votes

Check that to calling pushViewController before viewDidAppear is not safe. So you should create your code according to that.

0
votes

Try modifying line to

[self.navigationController pushViewController:options animated:YES];

Update

If you don't care about normal back button, try below code.

- (void) viewDidLoad
{
// ADD BELOW CODE IN viewDidLoad ALONG WITH REST OF YOUR CODE
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@”back”
style:UIBarButtonItemStyleBordered target:self action:@selector(backBarButton:)];

self.navigationItem.leftBarButtonItem = backButton;

}
- (void) backBarButton:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

You can play around with style to set your desired button style.