0
votes

Since I'm using a tapku calendar I want to fire a manual segue when a date is pressed. So I instantiate the view controller that I want to segue to, the segue, and then perform the segue.

DisplayScheduleViewController *vc = [[DisplayScheduleViewController alloc] init];

mySegue = [[UIStoryboardSegue alloc] initWithIdentifier:@"Day G" source:self destination:vc];

[self performSegueWithIdentifier:@"Day G" sender:self];

}

However, the program crashes once a date is pressed and this is the exception message:

terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'Day G''

also before running the program i get this warning message in the storyboard:

Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.

Do you know how to make it work?

Thanks

3
Do you already have a segue hooked up in the storyboard to a DisplayScheduleViewController? - rdelmar
I can't have a segue hooked up because I'm seguing from the cells of a tapku calendar. That's why I have to manually segue. Do you know how to do it correctly? - user1601259
Do you have anything in the storyboard now? If so, what? - rdelmar
The whole purpose of segues is to make transitions between view controllers in the storyboard easy to do. You probably don't want to do a segue in this case. So, what you need to do depends on your controller structure and how you want to do the transition. - rdelmar

3 Answers

4
votes

Here's how you can wire up a segue up in a storyboard and the invoke it from code:

  1. Create the two view controllers in the storyboard.
  2. Control drag from the view controller icon in the source scene to the destination scene.
  3. Choose the appropriate type of segue.
  4. In the inspector, assign an identifier to the segue.
  5. At runtime, from the source view controller, invoke

    [self performSegueWithIdentifier:<#identifier#> sender:nil];

  6. Override -[UIViewController prepareForSegue:sender:] in the source view controller to pass state between the source and destination controllers.

As an aside, the -[UIStoryboardSegue initWithIdentifier:source:destination:] method is there for you to override when creating custom segues subclass that will be instantiated from the storyboard. Creating storyboard segue instances directly like this isn't applicable.

0
votes

This warning:

Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:.

means you do not have a starting VC. I am guessing this has caused the segue problem as well. It looks like you are instantiating a VC and firing a segue from your code above, but are you actually in a VC in your code above?

I would recommend that you add the ViewController directly in your storyboard (graphically) and just change its class - here is a standard process but you can start based on where you are in your project

  1. Start a new project and just pick the template "Single View Application"
  2. Go to the storyboard of your project
  3. Open the utilities menu (right).
  4. Drag a second View controller object from the list on the bottom of the utilities menu and drag it to your storyboard - now you will have 2 View controllers (the one that came with the template - which is assigned automatically as the entry point- and the new one you added)
  5. Select the second view controller you added in your storyboard
  6. Go to the "identity inspector" in the utility menu
  7. Change the class of the second VC to your class name. Now you have 2 View controllers
  8. Now you have created the 2 VCs in the storyboard.
  9. Now you could include your code above in the first VC code.

Hope this helps

0
votes

If you cant set up a segue in StoryBoards, your best chance is probably setting up a new xib (outside of Storybards), designing your ViewController in that xib, and then instantiating that vc via UIViewController's initWithNibName: bundle: You can then present your vc using presentViewController: animated: completion:. Take a look at the docs for UIViewController if you are unsure how to use these methods, but i find them quite self-explanatory.

Using segues only works well if you can set them up in Storyboards and, AFAIK, they are pretty much useless without it.

BTW: that warning you are getting just means that the VC, which you have probabaly set up in Storyboards, does not have an Identifier for it to be instantiated. Going to StoryBoard identity inspector for that vc and entering a arbitrary name in "Storyboard ID" will suppress that.

Have fun