Key Concepts: Storyboards
The Storyboard is a visual representation of the user interface in your app. You can drag and drop different user interface elements, which are UIView subclasses (like UIButton) and when you run the app, they will be instantiated by the Storyboard as you placed them.
ViewControllers are individual screens in your app. Each viewController is an instance of the UIViewController class.
- You learned to subclass UIViewControllers and have the storyboard instantiate an instance of your class when the app starts.
Views that you have added to your Storyboard can be referenced by defining their outlets.
- To create an outlet you can open the Assistant to show your ViewController.m file side by side with your Storyboard. You then drag from the view to your code.
- Outlets are defined in the @interface section. It is common to keep the outlets in the @interface section of the .m file.
- Name your outlets as nouns, it is also good practice to include the class type as a reminder, eg. likeButton, addressTextField, etc.
Views typically have actions. The most common is that: a button is tapped. Actions can be "hooked up" to your code.
- We create an action in the same way we create an outlet. Instead of dragging into the @interface however, we drag into the @implementation
- Try to name your actions so they sound like events, eg: onLikeButtonTapped, onAddressTextFieldEntered, etc.
All objects are instances of classes. All objects have a variable: self. Inside class methods self refers to that instance of the object. In most of your code self will refer to an instance of a UIViewController, but this is just because most of the time we are writing UIViewController subclasses.
Back to Top