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 Amazon.com 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.
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!
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.
Since I asked it to place blue as the backgroundColor of self.window, this is what we get:
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.
Not so bad. Feelin nice!
Thank you.