0

I have 3 viewControllers. viewController1 is linked to viewController2 (via segue id "first"), and viewController2 is linked to viewController3 (via segue id "destinationController"). I'm trying to segue from viewController1 to viewController3. Here is my code:

UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];
[self.navigationController pushViewController:controller animated:YES];

It crashed with the following error:

'Storyboard (<UIStoryboard: 0x7fb1a944be00>) doesn't contain a view controller with identifier 'DestinationController''

How can I segue 2 viewControllers without connecting the first to the last? (I prefer not adding a segue from the storyboard because it will get very messy.)

Horray
  • 693
  • 10
  • 25
  • You can't do that; a segue has to be connected in the stryboard. But what you're doing in your code isn't a segue anyway. What you have, should work if viewController3 has the identifier "DestinationController". – rdelmar Apr 22 '15 at 03:57
  • vc2 is connected to vc3 with the identifier of DestinationController – Horray Apr 22 '15 at 03:59
  • I don't know how you could get the error you're getting then, because it's saying that you don't have a controller with that identifier -- I think what you have is a segue with that identifier. You need the identifier on the controller (storyboard ID in the Identity Inspector). – rdelmar Apr 22 '15 at 04:02
  • You hit it on the dot!! Thanks!! – Horray Apr 22 '15 at 04:05
  • Which way is recommended, `instantiateViewControllerWithIdentifier`, or should I just add a segue from vc1 to vc3? – Horray Apr 22 '15 at 04:06
  • They do the same thing, but I would use a segue as it makes the navigation between your controllers clearer. – rdelmar Apr 22 '15 at 04:08
  • Thanks!! Can you post that as an answer so I can accept it? – Horray Apr 22 '15 at 04:10
  • @Horray: " DestinationController" is your segue name or StoryBoardId – Vineesh TP Apr 22 '15 at 04:24

3 Answers3

0

Please check "DestinationController" segue is bind with you current ViewController in which you write this code.

If you perform segue from VC1 to VC3 there is only one way in your case you have to go through VC2 (You can place conditions on viewDidLoad method of VC2 to perform segue with VC3).

Please bind "DestinationController" to your current controller and your error will gone.

This may help you :)

Ajay Gabani
  • 1,168
  • 22
  • 38
0

The error is telling you that you don't have a controller with the identifier, "DestinationController". From the text in your question, it seems that you have a segue identifier called "DestinationController", but that's a different thing from an identifier on the controller, which you set in the Identity Inspector with the "Storyboard ID" field.

I think it would be more consistent though, to make a segue from the first to the third view controller. It also makes the navigation among your controllers clearer in the storyboard.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
0
UIViewController3 *controller3 = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];
[self.navigationController pushViewController: controller3 animated:YES];

Don't forget the set the storyboardId "DestinationController" not the segue name, Check the below Link,

Check the answer

Community
  • 1
  • 1
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130