0

Depending on the user's action, I need to move the user from one view controller to another depending on if they complete a task by time or complete a task by pressing a button. Both call the same method completeSession()

I've gone into the storyboard and added a Storyboard ID for each screen that is the same as the view controller class. So for this question, class JournalViewController has a storyboard ID of JournalViewController, same with SecondViewController

func completeSession() -> Void {
    ... some other stuff, unrelated ...

    let journalViewController = self.storyboard?.instantiateViewControllerWithIdentifier("JournalViewController") as ViewController
    self.presentViewController(journalViewController, animated: true, completion: nil)
}

This isn't working and causing my app to crash with a reason: Storyboard <UIStoryboard> doesn't contain a view controller with identifier JournalViewController, yet JournalViewController.swift contains:

class JournalViewController: UIViewController, UITextView Delegate {

Any idea how to push from SecondViewController to JournalViewController without error?

Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151
  • 1
    Storyboard identifiers are not class names. Do you have a view controller laid out in your storyboard which has the custom class `JournalViewController`? If so, then use the Storyboard ID of that view controller. – Jeffery Thomas Jan 10 '15 at 02:47
  • The class when I open the right panel and go to the identity inspector says Class JournalViewController – Zack Shapiro Jan 10 '15 at 02:49
  • Forgive my ignorance, would love for you to help me understand what the difference is between storyboard identifiers and the class names of the view controllers in their respective .swift files, aren't they the same thing? – Zack Shapiro Jan 10 '15 at 02:50
  • 1
    Storyboard identifiers are not found in .swift files. They are a part of .storyboard files. View controllers which are laid out in a storyboard can have a Storyboard ID set. This is the storyboard identifier. In a storyboard, select a view controller. Go to the Identity Inspector. In the Identity Inspector, you will see a group called Identity. In that group, there is a text field Storyboard ID. – Jeffery Thomas Jan 10 '15 at 03:05

2 Answers2

0

I think you can probably check the post here: What is a StoryBoard ID and how can i use this?

So, you have to understand how you can connect your code with your graphics. Before Storyboard comes out, we use NSBundle to load the graphics. So, the same thing here is how you are going to load your graphics. Because Storyboard does not simply just contain one screen. So, you will have something to identify them. That's why we need that.

Community
  • 1
  • 1
Lucas Huang
  • 3,998
  • 3
  • 20
  • 29
  • Okay, got it. So I've gone ahead and done that. Each screen has a storyboard ID that's the same name as the respective view controller class name. I'll update the original question so that an answer to this can be provided – Zack Shapiro Jan 10 '15 at 05:15
  • 1
    Not really you have to give all the screens a name. You only need to give them a name if you need to instantiate them using **UIStoryboard** – Lucas Huang Jan 11 '15 at 22:52
0

To answer my own question, this code worked, the missing piece was going into Storyboards and giving each item a storyboard ID.

instantiateViewControllerWithIdentifier relies on your storyboard ID to grab it successfully so that the app knows where to push the user to.

I hope that helps.

let journalViewController = self.storyboard?.instantiateViewControllerWithIdentifier("JournalViewController") as JournalViewController
self.presentViewController(journalViewController, animated: true, completion: nil)
Zack Shapiro
  • 6,648
  • 17
  • 83
  • 151