3

For an iOS app, I have a story board and multiple controllers, and a segue going from controller GameClass to controller SettingsClass. The segue, in view Controller GameClass has an identifier called GameToSettings:

enter image description here

However, when I want to call the segue from my GameClass:

[self performSegueWithIdentifier: @"GameToSettings" sender: self];

I get the error message

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<GameClass: 0xcf0c550>) has no segue with identifier 'GameToSettings''

I tried many tips I found in other articles (like renaming the storyboard, cleaning the project, changing simulator format, giving another name to the segue, ), but the issue keeps coming.

I've uploaded a version of my code here: http://www.petits-suisses.ch/Issue.zip. Any suggestion of what I could continue trying ?
Thanks.

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • Upload your project somewhere and post a link here, I'll have a look at it. – duci9y Jul 29 '14 at 17:13
  • is the settings controller embedded in a navigation controller? – hackerinheels Jul 29 '14 at 17:27
  • The flow is the following: Navigation controller -> Menu Controller --(presentViewController)-> Game Controller --(performSegueWithIdentifier)-> Settings Controller. – Laurent Crivello Jul 29 '14 at 17:32
  • Duci9y: I've uploaded the code onto http://www.petits-suisses.ch/Issue.zip. Click on the red dot, then on the blue one. The error will then appear. Thanks for your proposal ! – Laurent Crivello Jul 30 '14 at 08:07

1 Answers1

8

You should not instantiate your view controller this way:

GameClass *myNewVC = [[GameClass alloc] init];

Instead, use

 [[UIStoryboard storyboardWithName:@"storyboard name" bundle:nil] instantiateViewControllerWithIdentifier:@"vc identifier">]

Edit: Take a look at https://github.com/mac-cain13/R.swift

It will allow you to instantiate it easily with autocompletion, type safe method: R.storyboard.main.myViewController

Antzi
  • 12,831
  • 7
  • 48
  • 74