0

I have a viewcontroller that features a form, once this has been submitted I need the app to move back to the 'home' page this is done with:

ITViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:@"home"];
[svc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:svc animated:YES completion:nil];

However once I have done this and try to click on any of the buttons on the 'home' page I end up with the error:

Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue. Push segues can only be used when the source controller is managed by an instance of UINavigationController.'

My storyboard looks like:

enter image description here

Email View controller is where we go back from from

Community
  • 1
  • 1
DevWithZachary
  • 3,545
  • 11
  • 49
  • 101
  • use this link http://stackoverflow.com/questions/23102978/swrevealviewcontroller-without-using-navigationcontroller/23105142#23105142 – Anbu.Karthik May 27 '14 at 14:16

1 Answers1

2

Replace your code with this:

ITViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:@"home"];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:svc];
[navcon setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:navcon animated:YES completion:nil];

Your problem is that you are presenting a ITViewController out of a navigation controller. Then you try to perform a segue. Since there is no navigation controller, your app crashes. Embed your ITViewController into a UINavigationController and it will work.

Edit:

By the way, if you just want to go back to the home view controller, I suggest instead of allocating a new view controller and present it modally, just make your navigation controller pop to its root view controller. Instead of:

ITViewController *svc =[self.storyboard instantiateViewControllerWithIdentifier:@"home"];
[svc setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:svc animated:YES completion:nil];

Do:

[self.navigationController popToRootViewControllerAnimated:YES];
The dude
  • 7,896
  • 1
  • 25
  • 50