EEC-492/693/793 iPhone Application Development

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

Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
Classes & Objects Computer Science I Last updated 9/30/10.
Anatomy of an iPhone Application Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Road Map Introduction to object oriented programming. Classes
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
IPhone Development Crash Course By Dylan Harris
Exploring the iPhone SDK Toyin Adedokun & Daniel Laughlin.
Object-oriented Programming Concepts
C++ fundamentals.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Microsoft Visual Basic 2005: Reloaded Second Edition
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
IOS with Swift Hello world app.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Object-Oriented Design Justin Callanan CS 597. Object-Oriented Basics ● Data is stored and processed in “objects” ● Objects represent generalized real.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Object-Oriented Programming Chapter Chapter
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CSC 205 Programming II Lecture 5 AWT - I.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming
CSC 222: Object-Oriented Programming
Visual Basic.NET Windows Programming
Microsoft Foundation Classes MFC
Object-Orientated Programming
Object-Oriented Programming Concepts
INF230 Basics in C# Programming
Programming Logic and Design Seventh Edition
University of Central Florida COP 3330 Object Oriented Programming
Chapter 1: An Introduction to Visual Basic 2015
iOS - First Application Anatomy
Advanced Object-Oriented Programming
OOP What is problem? Solution? OOP
Object-Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
EEC-492/693/793 iPhone Application Development
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Can perform actions and provide communication
Corresponds with Chapter 7
Week 6 Object-Oriented Programming (2): Polymorphism
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Can perform actions and provide communication
Object-Oriented Programming: Classes and Objects
EEC-492/693/793 iPhone Application Development
Object-Oriented Programming: Inheritance and Polymorphism
Workshop for Programming And Systems Management Teachers
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Review of Previous Lesson
Object-Oriented Programming
EEC-492/693/793 iPhone Application Development
CSC 581: Mobile App Development
Presentation transcript:

EEC-492/693/793 iPhone Application Development Lecture 3 Wenbing Zhao & Nigamanth Sridhar 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Outline Objective-C Property Model-View-Controller A primer on Objective-Oriented Design Building the Button_Fun app 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Declared Properties A convenience notation used to replace the declaration and implementation of accessor methods In class interface, declare properties @property BOOL flag Each property specifies a method with the same name as the property Each writable property specifies an additional method of the form setPropertyName In the class implementation, use @synthesize compiler directive to ask the compiler to generate methods @synthesize flag; 11/17/2018 EEC492/693/793 - iPhone Application Development

Objective-C Properties The @property declaration (in the .h file) is the Objective-C way of declaring the getters and setters @property attributes retain: tells the compiler to send a retain message to any object that we assign to this property => do not garbage collect it Nonatomic: tells the compiler don’t bother adding thread-safety protections 11/17/2018 EEC492/693/793 - iPhone Application Development

Objective-C Properties Dot notation: convenient way to accessing a property myVar = someObject.foo; Is equivalent to: myVar = [someObject foo]; someObject.foo = myVar; Is equivalent to: [someObject setFoo: myVar]; 11/17/2018 EEC492/693/793 - iPhone Application Development

Model-View-Controller Model-View-Controller (MVC) is a design pattern commonly used for GUI-based apps Model: the classes that hold your app’s data View: made up of the windows, controls, and other elements that the user can see and interact with Controller: binds the model and view together and is the application logic that decides how to handle the user’s inputs Goal in MVC: make the objects that implement these three types of code as distinct from one another as possible MVC helps ensure maximum reusability 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Model Manages the app data and state Not concerned with UI or presentation Often persists somewhere Same model should be reusable, unchanged in different interfaces 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development View Present the Model to the user in an appropriate interface Allows user to manipulate data Does not store any data Except to cache state Easily reusable & configurable to display different data 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Controller Intermediary between Model & View Updates the view when the model changes Updates the model when the user manipulates the view Typically where the app logic lives 11/17/2018 EEC492/693/793 - iPhone Application Development

Model-View-Controller 11/17/2018 EEC492/693/793 - iPhone Application Development

Model-View-Controller outlets actions Model Object 11/17/2018 EEC492/693/793 - iPhone Application Development

Object Oriented Programming Objects Classes Inheritance Polymorphism Taken from http://www.aonaware.com/OOP1.htm 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Objects Objects are the central idea behind OOP An object is a bundle of (instance) variables and related methods The concept of object makes it easier to capture and simulate the states and activities of real word objects programmatically A method is an operation which can modify an object’s behavior (by changing its variables) In general, variables in an object should be modified by one of the object’s methods 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Classes A class is a blueprint (i.e. specification) for an object A class does not represent an object; it represents all the information a typically object should have as well as all the methods it should have Instantiation: an object is created based on the class specification 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Inheritance A class C2 can be defined to be the subclass of another class C1 C2 inherits C1, i.e., C2 will have everything C1 has (both data and behavior) C2 can use, augment, or replace C2’s methods To do: what UIControl generic behavior is defined? Memory management NSObject C1 (superclass) Generic behaviors UIControl C2 (subclass) Specific behaviors UIButton UITextField 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Polymorphism Polymorphism refers to the ability of objects belonging to different classes to respond to the same message, each one according to an appropriate type-specific behavior The programmer does not have to know the exact type of the object in advance => the exact behavior is determined at run-time Different objects involved only need to present a compatible interface to clients Usually, objects types are often implemented as subclasses of the same superclass 11/17/2018 EEC492/693/793 - iPhone Application Development

Inheritance with Polymorphism If a Dog is commanded to speak(), it may emit a bark If a Pig is asked to speak(), it may respond with an oink Both Dog and Pig inherit speak() from Animal, but their subclass methods override the methods of the superclass Inheritance combined with polymorphism allows class B to inherit from class A without having to retain all features of class A; it can do some of the things that class A does differently Calling code can issue the same command (sending the same message) to their superclass and get different results 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Benefits of OOP Encapsulation: states (variables) are changed via appropriate methods rather than changed directly by calling code This drastically helps with understanding of the code and eliminating potential bugs Modularity: different programmers or teams can work on different independent objects Inheritance & polymorphism 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development The Button Fun App Creating the project Choose view-based application, name it “Button Fun” Creating the view controller Outlets and actions Adding actions and outlets to the view controller Chapter 3 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Xcode Generated Code Our view controller Button_FunViewController.h Button_FunViewController.m Content of the header file Our view controller is a subclass of UIViewController, which is part of the UIKit #import <UIKit/UIKit.h> @interface Button_FunViewController : UIViewController { } @end 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Outlets and Actions In the button fun app, we will have two buttons and one label, which we will create in the IB. The question is: how do we interact with them programmatically? The answer is: through outlets and actions Outlet: a special kind of instance variable by which our controller class can refer to objects in the nib file E.g., controller can read the text of a label or modify it Action: interface objects in our nib file can be set up to trigger special methods (i.e., actions) in our controller class E.g., when a user touches up (i.e., pulls a finger off the screen) within a button, a specific action method should be called 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Outlets Outlets are declared using the keyword IBOutlet, as in the example: @property (nonatomic, retain) IBOutlet UIButton *myButton; Actions are methods in the controller class (IBAction)doSomething:(id)sender; An action method has to return IBAction type (equivalent to “void”) If you want to know the control that triggered the action, you should provide the (id)sender argument In our app, we will use the sender arg. Because we want to know which button was tapped 11/17/2018 EEC492/693/793 - iPhone Application Development

Add Actions and Outlets to View Controller (part1) Add declaration to the header file to: #import <UIKit/UIKit.h> @interface Button_FunViewController : UIViewController { UILabel *statusText; } @property (nonatomic, retain) IBOutlet UILabel *statusText; - (IBAction)buttonPressed:(id)sender; @end 11/17/2018 EEC492/693/793 - iPhone Application Development

Add Actions and Outlets to View Controller (part 2) Add implementation to Button_FunViewController.m @synthesize statusText; // tell the compiler to automatically create the accessor and mutator methods for us - (IBAction)buttonPressed:(id)sender { NSString *title = [sender titleForState:UIControlStateNormal]; NSString *newText = [[NSString alloc] initWithFormat: @"%@ button pressed.", title]; statusText.text = newText; [newText release]; } Sender will point to the button that was tapped 11/17/2018 EEC492/693/793 - iPhone Application Development

Add Actions and Outlets to View Controller Add implementation to Button_FunViewController.m (void)viewDidUnload { self.statusText = nil; //you need to set any outlets your class has to nil // in viewDidUnload. } - (void)dealloc { [statusText release]; //release the outlet [super dealloc]; @end 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Creating the View in IB Double-click Button_FunViewController.xib Add a label towards the bottom of the view, and two buttons side-by-side in the middle of the view Pay attention to the guidelines while placing the controls Change the text alignment to centered at the inspector Double-click the label and remove existing text Add text “Left” to the left button, “Right” to the right button 11/17/2018 EEC492/693/793 - iPhone Application Development

Connecting Everything Connecting outlets: control drag from File’s Owner to the control 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Specifying Actions Bring up connections inspector by pressing ⌘2 (or Tools -> Connection Inspector) For left button, under the heading Events, select “Touch Up Inside” This is an event when the user’s finger lifts up from the screen and the last place it touched before lifting was inside the button Associate the event with the action Click the circle right of “Touch Up Inside” and drag over to the “File’s Owner” icon When the gray menu pops up, select “buttonPressed:” Repeat for right button 11/17/2018 EEC492/693/793 - iPhone Application Development

EEC492/693/793 - iPhone Application Development Trying It Out Save your project Select “Build and Run” Play with the app in the simulator Test on your device Rebuild the app for your device ssh the app folder to your device Respring on your device, you will see your app Tap on your app to start it 11/17/2018 EEC492/693/793 - iPhone Application Development