Reputation: 325
I have a mster detail app with Xcode5, SDK 7.0, using storyboard.
Here is a part of the storyboard:
The master is a tab bar controller, it has two tabs, I want to push a view to one of the them. So I ctrl + drag from the navigation controller to my new view controller("Add Category View Controller" in the above picture)
The root view controller of the navigation controller has a button, the button action is :
- (IBAction)addBtnPressed:(id)sender {
[self.navigationController performSegueWithIdentifier:@"toAddCetegory" sender:self];
}
Here will be an exception:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'toAddCetegory'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
But if I change this Button action codes to:
- (IBAction)addBtnPressed:(id)sender {
AddCategoryViewController *addVC = [self.storyboard instantiateViewControllerWithIdentifier:@"addCategoryView"];
[self.navigationController pushViewController:addVC animated:YES];
}
It can work well, the new view will show when click on the button.
I want to know what is wrong with my way in segue?
Any help appreciated!
Upvotes: 0
Views: 552
Reputation: 4447
You are performing the push segue from root view controller of the navigation controller (in you code) but you have connected the push segue to the navigation controller not to the root view controller(in storyboard). Try connecting the push segue to the root view controller and that would work.
Upvotes: 1