Join Todd Perkins for an in-depth discussion in this video Setting the calculator to add or subtract, part of Programming for Non-Programmers: iOS 7.
- View Offline
- Exercise Files
…Now, we'll look at what happens when you press the plus and minus buttons.…Note that we're not going to be doing math here.…We're just going to be setting the functionality to…say that the app is in addition or subtraction mode.…So, scroll down in View.m and find tappedPlus.…In here, we're going to run the setMode function.…Remember that you run a function by typing self…inside of square brackets and then the function name, setMode.…
In this case, mode receives an integer value, so we need to pass in an integer.…I'm going to send in one here.…Let's select this line of code, copy it with Cmd+C and paste it into tappedMinus.…Now, in tappedMinus, I'm going to change that one to a…negative one, so I'm going to put a hyphen right before that.…Now, in setMode, the first thing I'm going to do…is save the mode as the value that was passed in.…So mode equals m.…So for, when the plus button is tapped, mode will be one,…and when the minus button is tapped, mode will be negative one.…
On the next line, I'll set lastButtonWasMode equal to YES.…
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 function
- 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 project1m 55s
2. Programming Building Blocks: Variables
3. Programming Building Blocks: Functions
4. Programming Building Blocks: Conditional Statements
Using conditional statements5m 21s
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.