Here’s a cheat sheet I use to remind myself how to create a ViewController and View in iOS5.
1. Create the View Controller.
Drag View Controller control onto story board.
Create View Controller class.
Assign the class to the controller.
2. Create the View.
Drag generic view onto View Controller.
Create View class.
Assign view class to generic view.
3. Connect View Controller to View.
Do this via a private interface on the View Controller. Note this property has an IBOutlet marker to support XCode dragging of controller onto view.
#import "PhotoViewController.h" #import "PhotoView.h" @interface PhotoViewController() @property (nonatomic, weak) IBOutlet PhotoView *photoView; @end @implementation PhotoViewController @synthesize photoView = _photoView; @end
Now go back to the story board and, holding down the ‘control’ key, drag the yellow circle with the white paper inside up into the view.
Optional: Move AppDelegate classes to Supporting Files.
You don’t really need these cluttering up your file structure so you can optionally move them into ‘Supporting Files’.
That’s it! You’ve now got a controller hooked up to it’s view.