Join Todd Perkins for an in-depth discussion in this video Showing the total when the Equals button is tapped, part of Programming for Non-Programmers with iOS 8.
Now that we have everything else in place,…we can control what happens…when the equals button is tapped.…Now I want you to think of this in simple terms.…We have two sets of numbers,…the numbers pressed before the mode button…that is either plus or minus…and the numbers pressed after.…So we're either going to add or subtract those numbers.…So let's go inside the tap equals method…and the first thing that we want to do…is to make sure that a mode button was tapped.…So we want to see if mode is equal to zero…and if so, we don't want to…continue on with the equals method.…
We want to exit out of it by calling the return command.…So below the closed curly brace after the if statement,…we are going to create a variable…and we'll call this variable iNum…and this is going to be an integer.…We'll set it equal to the value that's inside of the label…so this is our second set of numbers.…To get that value, we can type…valueString.toInt and then…we'll have to add an exclamation point at the end.…
Remember toInt can possibly be null…
If you find you'd like to learn more, see iOS App Development Essential Training, Foundations of Programming: Fundamentals, or any of the other programming courses in our library.
- Installing Xcode
- Creating an Xcode project
- Configuring the iOS Simulator
- Understanding variables
- Connecting visual objects to variables
- Understanding functions, methods, and selectors
- Connecting a button to a method
- Using conditional statements
- Setting up the user interface
- Connecting code elements to build an app
Skill Level Beginner
1. Setting Up Your Coding Environment
Creating an Xcode project3m 38s
2. Programming Building Blocks: Variables
3. Programming Building Blocks: Functions
4. Programming Building Blocks: Conditional Statements
Using conditional statements4m 11s
5. Building Your First Full Application
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.