How to Connect Viewcontroller.Swift to Viewcontroller in Storyboard

How to connect ViewController.swift to ViewController in Storyboard?

  1. Choose your ViewController in the storyboard or scene list (mine is called Circuit).
  2. Click on the Identity Inspector on the right
  3. Select Custom Class > Class > Type name of your swift file.

DONE :)

Here are these two steps on image (ugly i know)

How to link storyboard to view controller

I fixed the problem.

I modified call method.

let storyBoard : UIStoryboard = UIStoryboard(name: "ChatViewController", bundle:nil)
let chatViewController = storyBoard.instantiateViewController(withIdentifier: "ChatViewController")
self.navigationController?.pushViewController(chatViewController, animated: true)

Thank you for your kindness advice.

How to connect storyboard to viewcontroller

Unless I'm misunderstanding what you're asking, it's still there. Here are the steps to assign a custom view controller class to your view controller:

  1. Choose your view controller in the list of scenes on the left side.

Choose view controller screenshot


  1. Choose the Identify Inspector on the right side.
  2. Choose the custom view controller class from the Class list.

Choose custom view controller class screenshot

Main.storyboard not connecting to viewcontroller.swift

Here is a quick guide for how to properly add a new View Controller.

  1. Create a new ViewController.swift using the keyboard command cmd+n. Choose the Cocoa Touch Class

    step 1

  2. Name it whatever you want & make sure it's a subclass of UIViewController
    step 2

  3. Create and save the new .swift file. Now, copy the name of your view controller.

    step 3

  4. In your storyboard, create a new view controller and select it.

    step 4

  5. On the right hand side, under Custom Class, insert the new view controller's name (you should have copied that, so just hit paste) and hit enter

    Sample Image

Hope that helps :)

Trouble Linking Newly Created View to View Controller Class in Storyboard

To connect your ViewController.swift files to the ViewControllers, do the following:

  1. Select the ViewController in Storyboard.
  2. Navigate to the Identity inspector on the right panel.
  3. In the field Class, select the dropdown arrow.
  4. Select your ViewController.swift file that you would like to link to the ViewController in Storyboard.

This is a very easy step to miss. I've done it myself many times before. For future reference, when creating a new ViewController in Storyboard, connect it to its ViewController.swift file as soon as possible. Otherwise, it may result in incorrect Interface Builder connections, etc.

Adding Multiple View Controllers to ViewController.swift From Storyboard UI

If I understand correctly, you have multiple view controllers all with the same class "ViewController" that you want to duplicate and edit all the same way? You have to label each class differently or else the system crashes its like having twins and naming them all the same name and getting confused why they dont know which one you are talking to.



Related Topics



Leave a reply



Submit