Making a View Controller without storyboard, without xibs

Let’s walk through building a ViewController entirely in code.

Large portions of this tutorial were borrowed from iOS7 Programming Cookbook- check it out on if you are interested in trying out pure code examples by yourself

This isn’t as hard nor scary as it would initially seem..

Lets create an Empty application, then add on a ViewController file. You need the file, because that’s what we’ve always needed with storyboard, and xib files. Once you have that import the “ViewController.h” file into your AppDelegate implementation.

Screen Shot 2014-07-23 at 9.08.30 AM

Okay- now that we have that, we need to tell the AppDelegate what to do with it.

Did you guess what we needed next? If you guessed a ViewController property then know I am cheering for you!

Screen Shot 2014-07-23 at 9.10.55 AM

Scroll down and find application:didFinishLaunchingWithOptions method. It returns a BOOL and should be the first one. Initialize the vc property and set it to be the rootViewController.

Screen Shot 2014-07-23 at 9.18.01 AM

Since I asked it to place blue as the backgroundColor of self.window, this is what we get:

Screen Shot 2014-07-23 at 9.19.14 AM

So wait- how do we really know that it worked? I’m glad you asked!

Lets hop into the ViewController and throw down something… anything is fine!

The only issue you should be aware of is once you start doing things programmatically, the rest should be programmatic as well!

I dropped in a UISlider property, set its size, placed it in the center, min/max values, and added it to the subview of the ViewController all within the ViewController implementation file. AppDelegate doesn’t know it exists.

Screen Shot 2014-07-23 at 9.28.44 AM

Not so bad. Feelin nice!

Thank you.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s