Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Clicking on the link for the.tns file gives you will get the following screen: Select Save File and click OK.
Learning the Basics – Lesson 1
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
Anatomy of an iPhone Application Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Getting an account with WordPress.com Open your web browser ( mozilla firefox, internet explorer, opera, etc.,)
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Customizing Forms and Writing QuickBooks Letters Lesson 15.
Office XP Introductory Concepts and Techniques Windows XP Edition M i c r o s o f t Windows XP Project An Introduction to Windows XP Professional and Office.
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
® IBM Software Group © 2006 IBM Corporation Creating JSF/EGL Template Pages This section describes how to create.JTPL (Java Template Pages) using the Page.
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
Customizing forms and writing QuickBooks Letters Lesson 15.
Copyright © Texas Education Agency, All rights reserved. 1 Web Technologies Website Development with Dreamweaver.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Using Dreamweaver. Slide 1 Dreamweaver has 2 screens that do different things The Document window where you create your WebPages The Site window where.
Project 3 File, Document, Folder Management, Windows XP Explorer Windows XP Service Pack 2 Edition Comprehensive Concepts and Techniques.
Advanced Forms Lesson 10.
Web Technologies Website Development Trade & Industrial Education
Xcode testing Using XCTest.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
Website Development with Dreamweaver
iOS components in Swift
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Database Applications – Microsoft Access Lesson 6A Designing Custom Forms Updated F13 24 slides in presentation 1.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 2 The Visual Basic.NET Integrated Development Environment.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
Key Applications Module Lesson 21 — Access Essentials
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
HTML, Third Edition--Illustrated Introductory 1 HTML, Third Edition Illustrated Introductory Unit G Using Forms to Control Input.
IOS with Swift Hello world app.
IReport Demo Spring 2008 OEDSA Conference. Report Properties.
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
Basic Editing Lesson 2.
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Lesson No: 6 Introduction to Windows XP CHBT-01 Basic Micro process & Computer Operation.
 To begin you first need to sign up to Weebly by going to or alternatively and we will create an account.
HONG KONG TAOIST ASSOCIATION WUN TSUEN SCHOOL Microsoft PowerPoint 2010 Chapter 2 – Slides Tasks.
Lecture 10 Using Interface Builder to create Mac Applications.
Know your computer Make a Folder Copy from Word to Composer Format the Font Change the Alignment Format the Background Format the Colors Insert a Picture.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
Home page Web page link 1 Web page link 2Web page link 3Web page link 4.
Creating and Editing a Web Page
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
UFCFY5-30-1Multimedia Studio Scripting for Interactive Media Using Interface Fields to Receive and Display Data to the User.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Getting an account with WordPress.com
Creating Oracle Business Intelligence Interactive Dashboards
iOS UI Components Sisoft Technologies Pvt Ltd
Chapter 2 – Introduction to the Visual Studio .NET IDE
Designing with Introspection
Comprehend. Create. Communicate. Achieve More.
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
Ioannis Pavlidis Dinesh Majeti Ashik Khatri
EEC-492/693/793 iPhone Application Development
Presentation transcript:

Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012

A little background… Last summer, to celebrate our 25 th wedding anniversary, we took the family on the ferry across the Bay of Fundy from Bar Harbor, Maine, to Yarmouth, Nova Scotia. We took the van and spent a week exploring. You don’t need an international driver’s license to drive in Canada, but the speed limit signs are all in kilometers per hour (kph). It would have been useful to have an app on my iPhone that converted mph to kph – I didn’t want to get a ticket for speeding!

Design and resources I thought this could be a fairly simple app. It would have an input field to enter your driving speed, a button to convert mph to kph, a button to convert kph to mph, and an output field to give you the result. Just to make the app more graphically interesting, I thought the buttons should look like the speed limit signs typical of the US and Canada. I also realized that these elements would have to fit in the top half of the screen to allow room for a keypad to enter the driving speed.

Setting up 1.I created a Single View Application project in Xcode. 2.In the Main.storyboard file I needed to create some objects to work with, namely two fields (input and output), two buttons, and two labels (for the buttons). I added one more label to display a message as well. The objects inherit their methods and properties from the UIKit superclass. The fields, buttons, and labels are IBOutlets, of the type UITextField, UIButton, and UILabel respectively. Two method headers, IBActions for each button, are also declared. The code is on the next slide.

ViewController.h code MPHconverterViewController : UIViewController { (nonatomic, strong) IBOutlet UILabel *mph, (nonatomic, strong) IBOutlet UIButton *toMiles, (nonatomic, strong) IBOutlet UITextField *input, *output; -(IBAction) convertToMiles; -(IBAction)

Building the interface: fields 1.I added my images of the road signs to the Supporting Files folder of Xcode project and saved it. 2.I launched Interface Builder by clicking the Main.storyboard file. 3.From the Objects tab in the Library window I dragged two text fields onto the View window. For the field at the top (the input field) I set the Placeholder text in the Inspector window’s Attributes tab to be “Enter your driving speed here”. I also set the keyboard associated with both fields to be a Number Pad.

Building the interface: buttons 1.Next I dragged two Round Rect buttons into the view. In the View Size tab of the Inspector window I set the size of the buttons to 120 X 120 (the same size as my graphics). 2.In the Attributes tab of the Inspector window I set the Background of each button to the respective road sign graphic I wanted using the dropdown menu. I didn’t give the buttons titles.

Building the interface: labels 1.I dragged a Label for each button from the Objects tab of the Library window onto the View window, and set their Font to 30 points in the Attributes tab of the Inspector window. I deleted the default text in each Label. 2.I dragged one more Label into the view for a message below the output field. I set it’s Font size to 24 point, and gave it the text, “Drive safely.” The text for all fields and labels was set to be centered.

Building the interface: connections 1.In the Document window I selected File’s Owner. In the View Controller Connections tab of the Inspector window I saw the four outlets and two actions I created in the ViewController.h file in Xcode. 2.I dragged a connection from each of the actions, toMiles and toKilos, to each of their respective buttons. 3.I dragged a connection for the input and output outlets to their respective fields (top and bottom). 4.I dragged a connection for the kph and mph outlets to their respective labels. Then I saved the file.

Implementing methods - design I wanted the app to display the user’s driving speed on the appropriate road sign (i.e. if they wanted to convert their mph to kph, I wanted their speed to appear over the mph button). However, I didn’t want the input text to persist or the previous conversion text to persist either. I wanted the button therefore to clear all fields each time it was pressed. I wanted to confirm for the user the unit of measurement in the output field, so I wanted to display the result of the calculation concatenated with the appropriate units (i.e. 65 Miles Per Hour). Finally, I wanted to dismiss the keyboard each time the button was pressed so the message behind it would be displayed.

Implementing methods - code The first line of the button code dismisses the keyboard by releasing the “first responder” status of the input field that called the keyboard in the first place, by a user clicking on it to enter some text. The second line performs the conversion calculation either by multiplying or dividing the value in the input field by The third line takes the value of the variable (k or m), concatenates it with the appropriate unit of measurement, and displays it in the output field. The fourth line creates a string from the input field and the fifth line displays it in the button label. The sixth and seventh lines of code clear the input field and the other button’s label by setting their text to nil. The code was written right above statement and the project was saved and built. The code for each button follows on the next two slides.

The toMiles button -(IBAction) convertToMiles { //dismiss the keyboard [_innput resignFirstResponder]; //Calculate kilos to miles and put that value into the output field float k=([input.text floatValue] /1.61); [_output setText:[NSString Miles Per Hour",k]]; //Put the input value into the label on the kph button NSString *confirmKPH=[[NSString alloc] _input.text]; [_kph setText:confirmKPH]; //Clear the input and mph fields [_mph setText:nil]; [_input setText:nil]; }

The toKilos button -(IBAction) toKilos{ //dismiss the keyboard [_input resignFirstResponder]; //Calculate miles to kilos and put that value into the output field float m=([_input.text floatValue] *1.61); [_output setText:[NSString Kilometers Per Hour",m]]; //Put the input value into the label on the mph button NSString *confirmMPH=[[NSString alloc] _input.text]; [_mph setText:confirmMPH]; //Clear the input and kph fields [_kph setText:nil]; [_input setText:nil]; }

Success!

What’s next? So what else would be useful to convert? Gallons to liters? Fahrenheit to Celsius? Feet and inches to meters and centimeters? Here’s a link to give you some ideas: Currency would be cool, but the relative values of currencies fluctuate, so the conversion formula would have to be regularly updated from data on the Internet – a lesson for another time. What about the message field in my example? Could it be more useful? Could its contents be dynamically determined as the result of a conditional statement? You’ve already shown me you can do a lot with these simple examples. So be creative and have fun!