Reputation:
i have one normal UIViewCOntroller(home) in which i have IBAction Method like
- (IBAction)goto1:(id)sender
{
self. goto1Controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:self. goto1Controller animated:YES];
}
it works fine. goto1Controller is a normal UIViewcontroller in which i have used one action through userdefined Navigation controller through which i go to another controller like in self.goto1Controller
- (IBAction)goto2:(id)sender
{
[userdefNavController pushViewController:goto2Controller animated:YES];
[self presentModalViewController: userdefNavController animated:NO];
}
i come back from goto2Controller to goto1Controller through
[self dismissModalViewControllerAnimated:YES];
it works fine...but when i use this same method([self dismissModalViewControllerAnimated:YES];) to go to home i have to press twice... and also when i press - (IBAction)goto2:(id)sender again after coming from goto2Controller crash is happened..error also "Pushing the same view controller instance more than once is not supported" any solution? i have in my viewdidload as
userdefNavController = [[UINavigationController alloc] initWithRootViewController:self];
Upvotes: 1
Views: 3876
Reputation: 24476
You should not necessarily be mixing presentModalViewController and pushViewController on the navigation controller. There are different reasons to use each of them. Here is what the view controller programming guide says:
Most commonly, applications use modal view controllers as a temporary interruption in order to obtain key information from the user. However, you can also use modally presented view controllers to implement alternate interfaces for your application at specific times.
I you have hierarchical data, create a drill down by displaying successive view controllers using -pushNavigationController:aniamted:. When the error message says you cannot push the same instance, it doesn't mean you can't create a new instance of the same class. Just create a new instance of the view controller you want to push.
If you have a special case in which you need to present something out of the ordinary to the user, the use -presetnModalViewController:
Upvotes: 4