Refactoring Moving a console app to a UI app. Refactoring Goal: change a console app to a UI app Principles: The main.m goes away The local variables.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

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.
Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
The Web Warrior Guide to Web Design Technologies
CSCI 171 Presentation 11 Pointers. Pointer Basics.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Creating Shareable Models By: Eric Hutton CSDMS - Community Surface Dynamics Modeling System (pronounced ˈ s ɪ stəms) Image by Flickr user Let There Be.
Guide To UNIX Using Linux Third Edition
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Telerik Software Academy ASP.NET Web Forms Data Validation, Data Validators, Validation Groups Telerik Software Academy
Xcode testing Using XCTest.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
GUI’s Part Two wxWidgets components. Resources for wxWidgets Sample code on course website wxWidgets web site.
iOS components in Swift
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
Objective-C OOP Spring OOP Conceptually the same as C++, Java, and all other object oriented languages The syntax, however… …is, well, different.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
IOS with Swift Hello world app.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
Create a Web View App Step-by-Step. Step 1 Create a new project in XCode using the "Single View Application" option.
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Gestures UIGestureRecognizer.
Passing data between storyboard views Singleton pattern.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 41 JavaServer Face.
CSCI 171 Presentation 6 Functions and Variable Scope.
Advanced Arithmetic, Conditionals, and Loops INFSY 535.
More Objective-C Details FA 172 Intro to Mobile App Development.
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
Learning to use a ‘For Loop’ and a ‘Variable’. Learning Objective To use a ‘For’ loop to build shapes within your program Use a variable to detect input.
Chapter 4 Assignment Statement
“Form Ever Follows Function” Louis Henri Sullivan
Chapter 2 Elementary Programming
HW7(100pts+10bonus) The homework Due on May 11, 23:59:59
Chapter 3 Assignment Statement
CompSci 230 Software Construction
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Department Array in Visual Basic
Integrating JavaScript and HTML
Programming Lists of Data 靜宜大學資管系 楊子青
EEC-492/693/793 iPhone Application Development
Presentation transcript:

Refactoring Moving a console app to a UI app

Refactoring Goal: change a console app to a UI app Principles: The main.m goes away The local variables in the main.m file become instance variables in the new viewController.m The functions that implemented console interactions with the user become IBAction methods for various UI components Other classes in the console app are imported as are to the UI app For the code for these slides, see the class web site, References->Examples->AlienRefactored

Creating the project Create new single view project I named mine “alienRefactored” You get the appDelegate and the ViewController.m Now import the class files (but not the main.m file) from the old project File  Add Files to “AlienRefactored” See next slide for the dialog box

Creating the project Check this box Choose the files

Main.m Does not exist in the new project (that we can see) Open main.m from the old project. Use code If there were local variables, make them instance variables See next slide

XXXViewController.h #import #import "alien.h” static const int NUMALIENS = CMPViewController :UIViewController{ alien *george, *sally; double timeToHome; double timeToPlace; double theSpeed; double theDistance; id Import any class you use Make constants that you need. These must be static

XXXViewController.h - (void) viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. nextIndex = 0; } Use viewDidLoad method to initialize variables and initialize any dynamic memory.

Designing the interface See where the console app asked for input printf(“enter alien name:”); scanf(“%s”, theName); printf(“enter number of eyes:”); scanf(“%d”, numEyes); printf(“enter distance to home:”); scanf(“%f”, theDistance); printf(“enter speed of ship:”); scanf(“%f”, theSpeed); These become UITextFields You’ll need IBOutlets to access them in your code. You’ll also need a button to determine when to add this alien

Interface

Connections Create IBOutlets for the fields Create IBAction for the button

IBActions Fill in the action methods − (IBAction)addAlien:(UIButton *)sender { NSString *thePlanet = _nameField.text; theSpeed = [_speedField.text doubleValue]; theDistance = [_distanceField.text doubleValue]; int numEyes = [_numEyesField.text integerValue]; george =[[alien alloc] initWithNum: numEyes andDistance: theDistance andPlanet: thePlanet]; if (nextIndex < 5) { theAliens[nextIndex++] = george; next alien lives at and is %f miles from home at %f speed", ((alien *)theAliens[nextIndex - 1]).planet, ((alien *)theAliens[nextIndex - 1]).distanceToHome, ((alien *)theAliens[nextIndex - 1]).speedSpaceShip); } Print to the console as an error check If you don’t properties, their getters and setters are preceded by an underscore (‘_’)

Fix the keyboard Connect to this method from every text field

Fix the keyboard Add the action method for the text fields − (IBAction)didFinishEditing:(UITextField *)sender { [sender resignFirstResponder]; }

Put in appropriate error messages Array is full in - (IBAction)addAlien:(UIButton *)sender if (nextIndex < MAXALIENS) { // previous code else{ // the array is full UIAlertView *alert = [[UIAlertView alloc] Alert!" many Aliens!" delegate:nil otherButtonTitles:nil]; [alert show]; }

Add more buttons Each console option must have a component (usually a button). Add more buttons and fields as necessary. Hide components to minimize clutter

More Buttons Add components to perform other functions from the console app

Connect the new components I would also add an IBOutlet for the new field.

Add bodies for the Action methods For our “Calc Time” button - (IBAction)calcTimeHome:(UIButton *)sender { // pick an arbitrary alien if (nextIndex > 0){ float timeHome = [((alien *)theAliens[0]) calcTimeToHome]; // put the value into the text field _timeToHome.text = [NSString timeHome]; } If you don’t properties, their getters and setters are preceded by an underscore (‘_’)