0
votes

I have 3 view controllers in my UINavigationController. If I use pushViewController and popViewController to switch between view controllers, everything is okay.

But if I invoke setViewControllers in order to re-arrange their order, I get crash when I touch backward navigation bar button.

[UIBarButtonItem performSelector:withObject:withObject]: message to deallocated instance.

Original stack is A and B, and next I've set A and C like bellow.

[delegate.navigationController setViewControllers:[NSArray arrayWithObjects:[[delegate.navigationController viewControllers] objectAtIndex:0], controllerC, nil] animated:YES];

What I've found strange is..., if I invoke that method with animated:NO, crash does not occur.

What is the secret of animated parameter for my code? help me please...:(

2

2 Answers

1
votes

The fact that it only happens with animated:YES has me thinking it's an autorelease race-condition. Are you allocating your controllerC instance with autorelease? If so, try avoiding that and explicitly releasing it after the call to setViewControllers instead. Let me know if that solves your issue.

Can't claim I fully understand what's happening here, but give that a shot.

-S

0
votes

I had that same issue, and it sure seemed like an iOS bug to me. The work-around that worked for me was to first push the new view controller:

[navigationController pushViewController:controllerC animated:YES];

Then set the stack of view controllers to the proper value (to eliminate the ones in between):

NSArray *newViewControllers = [NSArray arrayWithObjects:controllerA, controllerC, nil];
[navigationController setViewControllers:newViewControllers animated:NO];