View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.

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

Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
IOS and AddressBook CS4521. Address Book UI Framework Exploring Contacts.
Using Multiple Forms! Creating a Splash Screen. Uses of Multiple Forms Includes: Dialog Boxes (appear often in Windows Programs) Splash Screen (a window.
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
Getting Started with Layout Compiled by Ryan Johnson May 1, 2002  Open Orcad Capture under Engineering Software  Under FILE, choose NEW, PROJECT  The.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
The Problem: iPhone UI Navigation I want to have a TableView that works INSIDE a TabView.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
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.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Alice Variables Pepper. Set to Java look Edit / preferences restart.
Introduction To Form Builder
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.
Introduction to Apps Development for the iPhone and the Android OS Art Gittleman Professor, Computer Science Calif State Univ Long Beach Feb 28, 2011.
BoardMaker Ver 6 Creating Interactive Activities for the Classroom.
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
A First Program Using C#
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.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Web Design Using HTML Codes. WHAT DO I NEED TO BEGIN DESIGNING A HOME PAGE? 1.YOU NEED A FOLDER (also called a DIRECTORY) You should set up a folder or.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Xcode testing Using XCTest.
| | Tel: | | Computer Training & Personal Development Outlook Express Complete.
iOS components in Swift
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
1 Designing with a UIToolBar iPhone/iPad, iOS Development Tutorial.
Objective-C OOP Spring OOP Conceptually the same as C++, Java, and all other object oriented languages The syntax, however… …is, well, different.
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.
Chapter 5 Quick Links Slide 2 Performance Objectives Understanding Framesets and Frames Creating Framesets and Frames Selecting Framesets and Frames Using.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
1 Chapter 12: Form Builder Objects and Flexible Code.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Microsoft Outlook 2010 Chapter 3 Managing Contacts and Personal Contact Information with Outlook.
Gestures UIGestureRecognizer.
Course Summary Xcode & iPhone Simulator
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
Microsoft Visual Basic 2012 CHAPTER ELEVEN Multiple Classes and Inheritance.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
Editing Basics Lesson 8. Skills Matrix SKILL #MATRIX SKILL 2.2.1Cut, copy, and paste text 2.2.2Find and replace text 4.1.1Insert building blocks in documents.
OOP with Objective-C Categories, Protocols and Declared Properties.
The Controller in MVC of iOS CS4521. The controller in the MVC  Controller  Knows about model and view objects  The brains of the operation  Manages.
The desktop (overview) Working with desktop icons The desktop is the main screen area that you see after you turn on your computer and log on to Windows.
Lecture 10 Using Interface Builder to create Mac Applications.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
IOS Programming Medialogy, Semester 7, 2010 Aalborg University, Aalborg David Meredith
Folio3 IPhone Training Session 2 Testing App on device Presenter: Imam Raza.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
When iPhone users to want to sync songs or pictures to their device, they can take advantage of iTunes and sync the whole playlist or folder to their.
Course Summary Xcode & iPhone Simulator
iOS - First Application Anatomy
EEC-492/693/793 iPhone Application Development
Affordable iPhone Mobile Apps Development Services Company
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
Presentation transcript:

View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson

Important concepts to review Objective-C instance variables go in the header file, inside declaration, always with the type and, if they’re objects, the pointer (*) character. Objective-C method declarations go in the header file, outside block, in the following form: - (returntype) methodName: (parameter1type) parameter1 parameter2Name: (parameter2type) parameter2... ;. Alternately, you can put a method declaration (or only its implementation) in the.m file, if you don’t want other classes to be able to see it.

…more concepts to review Objects are created in code (usually with alloc and init) or withInterface Builder. To work with objects created in Interface Builder, declare instance variables as IBOutlets and event-handling methods as returning IBAction. Then wire the connections in the nib file with IB. Be sure to save the file in IB before you build the project in Xcode.

…more concepts to review To implement a delegate protocol, add the protocol name in angle braces to your header statement, after the name of the class you’re subclassing. Then, in the implementation (.m) file, implement all required methods as well as any others you’re interested in.

…additional concepts to review Declare properties with declaration in the header file, and then in the implementation to have the compiler create the getters and setters for you. Add to the provided implementation of dealloc to release any instance variables your object may be retaining.

View Controllers Each screen in your iPhone application is managed by a view controller (VC) that is in charge of displaying the view and responding to just about every action the user can take on that view. Your view controller is the C in MVC (Model View Controller). It needs to communicate with both the view and model parts of your application.

The Movie project sample Name of project: Movie Open the MovieViewController.xib file in Interface Builder by double-clicking it. Add a button to this initial view and have that button invoke an action method on the view controller. Set its title to Edit by double-clicking in the center of the button and then typing Edit.

Implementing a Button Action The button should do something when the user taps it. Open the MovieViewController.h file in Xcode, and add this line to it just before compiler directive: - (IBAction)edit;

Making a connection in IB Save your work in Xcode, and head back to IB to connect the button to this action. The target is the File’s Owner, and the action is the edit method. Setting that target/action pair is what causes the button to invoke the edit method when it’s clicked.

Implementing the method In the MovieView-Controller.m file. Open the file in Xcode, and add some code between compiler directives that looks like this: - (IBAction)edit { method invoked" ); }

Models In iTunes, classes like Song or Podcast and the actions they support like play form the model. In iPhoto, it’s classes like Photo or Album. To build a serious application, you need a real model. A real model captures the essence of an application.

Building a Model We’ll build a Movie class to play the part of our model. We will then use an instance of our Movie class to hold the data and modify the existing UI to display the data. The view controller will be the glue that is connected to both the model and the view.

Creating the Movie class Select the Classes group in Xcode, and then right-click and select Add > New File from the pop-up menu. In the dialog box that opens, choose Cocoa Touch Classes > Objective-C Class. In the “Subclass of” pull-down, make sure to select NSObject, and then click the Next button.

Creating the Movie class Name the class Movie, and make sure to check the two checkboxes for adding the.h file and adding the file to the target.

Adding properties to classes Add three properties: – an NSString named title to hold the title of the movie, – an NSNumber named boxOfficeGross to hold the box-office sales, – and an NSString named summary to hold the plot summary text. Define a custom init method for our movie so we can initialize the three properties when we create a new movie.

Movie Class

Adding Outlets and Actions to the Controller This process requires jumping between IB and Xcode frequently. Add four properties and the instance variables The movie object that will be our model.

Adding Outlets and Actions to the Controller compiler directive on line 3 is a forward declaration, and it tells the Objective-C compiler that you know that it can’t find a class named Movie and that it should not report errors or warnings about not being able to find it. We use forward declarations because the compiler provides poor error reporting on include cycles.

MovieViewController.m Add statement for each of the properties and the import to the implementation file. for forward declaration you do in the header file, you have to import the header file for that class in the implementation file

Updating the UI Open MovieViewController. xib. Add three UILabels Connect the VC’s outlets to the labels

Implementing the Controller The movie’s data should be displayed on the screen. Create the movie object. Override the viewDidLoad method in the MovieView-Controller to create a new instance once the view that the MovieViewController controls is loaded.

applicationDidFinishLaunching the applicationDidFinishLaunching: method on the MovieAppDelegate class is called by the UIApplication object when it’s finished launching. The app delegate has two outlets that are connected in the MainWindow.xib nib file: window and viewController. – The window property is connected to the main window of our application – The viewController property is connected to our movie view controller

code for applicationDidFinishLaunching The app delegate is asking the window to add the viewController’s view as a subview.

When a view controller is asked for its view First, it checks to see whether it already has one. – If so, it just returns the already loaded view. – If it does not have one, then it calls the loadView method. That process runs more or less like this: – Is a nib filename set (typically set in IB but can be set via code)? – If so, load the nib file passing the view controller in as File’s Owner. – After the nib file is loaded, assert that the view has been set. If not, throw an exception and print an error message.

LoadView If a nib filename is not set on your view controller, then you need to build the view manually in the loadView. We can set the nib filename via IB, and we rarely if ever need to manually code a loadView method. Once the loadView method finishes, the viewDidLoad method is called. This is a great place for us to do initialization (such as create our Movie object) because it’s called only when the view is loaded.

viewWillAppear: method This method is called every time the view is about to become visible. A view can become visible and then be removed from view several times during the normal flow of an application. For example, consider the Contacts app; the list of all your contacts is shown each time you finish looking at or editing an individual contact, and the viewWillAppear: method is called each time.

Code for the viewWillAppear: method Hence, this method is the ideal place to set the values we want to appear on the view when it does appear.

Running Application