ipatch
ipatch

Reputation: 4033

How to associate new class files to be a view controller for a specific scene?

Alright, I will try and make this short and sweet. I recently created my first iOS app, and in my app I decided to go the storyboard route by selecting the checkbox when creating the project. On a side note, I recently just started developing in Xcode, keep that in mind. So I started by designing the GUI elements of my app, and before I knew it, I had 8 scenes in my storyboard file and one view controller. Needless to say the view controller has been populated with code from different scenes thus making it difficult to understand what does what in the view controller. In the spirit OO design principles, I thought it would be a good idea to create a separate view controller for each scene. So I created some class files for the project. When I try to associate the newly created class file with the scene my computer just sounds a beep / donk sound. I am trying to associate the newly created class file to a scene by selecting the scene in the storyboard / Interface Builder view, then displaying the Utilities pane on the right, then selecting the Identity Inspector at the top of the Utilities pane, then setting the Custom Class to my newly created class file, but when I type the name of the class and press enter I just hear a beep.

If any one has any insight or knows of a tutorial explaining this process please post. Part of the reason I am trying to do this is for code readability, better code management, and a better code structure for the application. I came across this stack thread explaining some of what I am talking about.

Also here's a picture of what my project looks like if that helps shed any light. enter image description here

Upvotes: 2

Views: 3352

Answers (1)

Kimpoy
Kimpoy

Reputation: 1974

You need to consider the parent class of your controllers, UIViewController for example. To do so, you must check the .h file and your xib/nib file.

I. In your .h file, you will be seing:

@interface ViewControllerWelcome : NSObject

Change 'NSObject' to 'UIViewController' - this will mean that ViewControllerWelcome has a parent class UIViewController.

II. In your nib/xib file:

1. Click on the controller that you are going to set from the storyboard.
2. Go to interface builder and click the "Identity Inspector" (third item from the left) from the Utilities panel. 
3. You need to specifically set each controller's name (eg. ViewControllerWelcome)

Do these to all controllers from your storyboard.

Here's something you can read about ViewControllers and Storyboards.

Upvotes: 3

Related Questions