In this section, we’re finally going to be in Xcode. We are going to start with a single window project. In the View Controller that comes with the project we are going to place some Views and hook them up to the code with IBOutlets and IBActions. Once the elements are hooked up, we’ll make it so touching the update button, takes the text from the text field and puts it into the label.
- Its probably best try to explain the difference between an IBOutlet and an IBAction. Its a pretty confusing concept. I usually like to explain them as different “directions” of communication.
- IBOutlets let your code tell the object in the storyboard to do something.
- IBActions let objects in the storyboard tell your code to do something.
- Instruct the students to change the background color of the View Controller in the storyboard and make sure that color shows up in the simulator.
- This will make sure everyone’s Xcode and Simulator are working properly.
- Lastly, make sure they change the Size under “Simulated Metrics” to match the size of the device they are using in the simulator.
- This makes it so we don’t need to worry about AutoLayout in this class.
- Reference Screenshot
- Instruct the students to drag in a UIButton, a UITextField and a UILabel.
- Connect 3 IBOulets (1 for each object in the storyboard) and 1 IBAction (for the button)
- Insert an NSLog statement into the IBAction and make sure all students can click the button to cause the log output.
- This is also a good opportunity to show how breakpoints can be used to make sure a button is working.
- Configure the code so tapping the button takes the text from the UITextField and puts it into the UILabel.
- Have the students experiment with typing text into the simulator and clicking the update button to move it to the label.
- Optionally, have the keyboard dismiss when clicking update
- Optionally, show how to get multiple lines of text in the text label.