Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classes for new View Controller in Storyboard

In my storyboard I drag on a new View Controller. My Storyboard now has two view controllers: the main one that came when I created the file, and the one a dragged on.

When I go into the 'assistant editor' and select the main view controller, I get the ViewController.h class. But when I select the other controller I get UIViewController.h which is an Apple file.

How do I link/create these classes for each View Controller? Is there an automated way to do this, or am I not doing it right.

like image 528
ecnepsnai Avatar asked Jul 07 '12 04:07

ecnepsnai


People also ask

How do I create a view controller in storyboard?

To create a new view controller, select File->New->File and select a Cocoa Touch Class. Choose whether to create it with Swift or Objective-C and inherit from UIViewController . Don't create it with a xib (a separate Interface Builder file), as you will most likely add it to an existing storyboard.

How do I change the initial view controller in storyboard?

Specifying the Initial View Controllerstoryboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller. Checking this box will identify the selected view controller as the initial entry point for the storyboard you're on.

What are the responsibilities of view controller?

Each view controller manages a portion of your app's user interface as well as the interactions between that interface and the underlying data. View controllers also facilitate transitions between different parts of your user interface.


1 Answers

You need to create your own subclass of UIViewController and set the newly created view controller as the custom class in the storyboard.

  1. Press cmd+n or go to File > New File
  2. Select Objective-C class and hit next
  3. Type UIViewController into the second box and type a name for the new class in the first box (which will be something like MyClassViewController)
  4. Go into your storyboard, select the View Controller you dragged out, look at the inspector and go to the Custom Class Tab and set the custom class to your newly created view controller (e.g. MyClassViewController)
like image 91
Chris McKnight Avatar answered Oct 11 '22 13:10

Chris McKnight