brian0
brian0

Reputation: 105

Adding a second View Controller to storyboard

I'm learning Cocoa, and I'm trying to understand the logic (behind the scenes) of the IB.
1) On a new xcode project (cocoa/obj-c) the storyboard starts with a
predefined View Controller (VC) which is "associated" with files ViewController.{h,m}.
2) I add a Push Button with name "Switch" to the the View.
3) I add a Second View Controller (VC2)
4) I connect (click-drag) "Switch" --> VC2 which create a "segue" VC-->VC2.
So far so good. If I click "Switch" on VC, the window of VC2 appears.
5) Now I want to add a label with name "Foo" to VC2 and connect "Foo" to some IBOutlet in my code.
I'm guessing that I need to create a new class "ViewController2"
which inherits from NSViewController and make the connection VC2 <--> ViewController2
in such a way that I can click-drag from "Foo" to the interface
of ViewController2 in ViewController2.h in order to create
an IBOutlet.

Question (finally): how do I make the connection
VC2 <--> ViewController2?

More generally: is there a good reference for understanding
the logic behind IB?

Upvotes: 1

Views: 918

Answers (1)

Swift Dev Journal
Swift Dev Journal

Reputation: 20088

You are correct that you have to create a NSViewController subclass for the second view controller. The next step to take is to set the second view controller's class to your subclass. Set the view controller's class using the identity inspector.

enter image description here

After setting the second view controller's class to your subclass, you should be able to create outlets and make connections from user interface elements in the second view controller to that view controller's source code file.

Upvotes: 2

Related Questions