Building GUIs with UIKit. Kevin Cathey

Similar documents
Designing iphone Applications

View Controllers CPRE 388

Structuring an App Copyright 2013 Apple Inc. All Rights Reserved.

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

Assignment III: Graphing Calculator

CSC 581: Mobile App Development Spring 2018

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

MVC & Onwards. CS 442: Mobile App Development Michael Saelee

Intro to Native ios Development. Dave Koziol Arbormoon Software, Inc.

iphone App Basics iphone and ipod touch Development Fall 2009 Lecture 5

InterfaceBuilder and user interfaces

View Concepts. iphone Application Programming Lecture 4: User Interface Design. SDK provide many types of Views to show your content

CS193P: HelloPoly Walkthrough

User Experience: Windows & Views

Mobile Application Development

Implementing UI Designs in Interface Builder

ios Development Lecture 3 Controllers of View Controllers Ing. Simone Cirani

ITP 342 Mobile App Dev. Table Views

Assignment III: Graphing Calculator

Widget Tour. iphone and ipod touch Development Fall 2009 Lecture 7

ITP 342 Mobile App Dev. Table Views

lecture 10 UI/UX and Programmatic Design cs : spring 2018

Apple Development Technology Workshops

Stanford CS193p. Developing Applications for ios. Fall Stanford CS193p. Fall 2011

Your First iphone OS Application

Cocoa Programming A Quick-Start Guide for Developers

iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department

Advanced ios. CSCI 4448/5448: Object-Oriented Analysis & Design Lecture 20 11/01/2012

iphone Application Tutorial

Announcements. Today s Topics

Why Model-View-Controller?

ITP 342 Mobile App Dev. Interface Builder in Xcode

1 Build Your First App. The way to get started is to quit talking and begin doing. Walt Disney

CS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding

Your First iphone Application

Navigation bar (Xcode version 4.5.2) 1. Create a new project. From the Xcode menu, select File > New > Project

IPHONE DEVELOPMENT. Getting Started with the iphone SDK

MVC and Interface Builder IAP 2010

CS193p Spring 2010 Monday, April 12, 2010

ITP 342 Mobile App Dev. Connections

ios Mobile Development

iphone Application Programming Lecture 5: View Programming

CS193E: Temperature Converter Walkthrough

Event Delivery: The Responder Chain

Objectives. Submission. Register for an Apple account. Notes on Saving Projects. Xcode Shortcuts. CprE 388 Lab 1: Introduction to Xcode

Mobile Application Programming. Messaging and Delegation

Developing Applications for ios

Introductory ios Development

Building an Application

Stanford CS193p. Developing Applications for ios. Fall CS193p. Fall

Object-Oriented Programming in Objective-C

Intro to Development for ios. Dave Koziol Arbormoon Software, Inc.

CS193P - Lecture 8. iphone Application Development. Scroll Views & Table Views

A Better MVC. 300 line view controllers or bust. Dave A guy who thinks too deeply about stuff

NATIVE APP INTERCEPTS on ios & ANDROID

AVAudioPlayer. avtouch Application

Today s Topics. Scroll views Table views. UITableViewController Table view cells. Displaying data Controlling appearance & behavior

Collection Views. Dr. Sarah Abraham

Stanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015

View Controller Lifecycle

User Experience: Windows & Views

Objective-C Primer. iphone Programmer s Association. Lorenzo Swank September 10, 2008

Stanford CS193p. Developing Applications for ios. Spring CS193p. Spring 2016

ios Mobile Development

Topics in Mobile Computing

Organization of User Interface Software

ios DeCal : Lecture 2 Structure of ios Applications: MVC and Auto Layout

Stanford CS193p. Developing Applications for ios. Winter CS193p. Winter 2017

Announcements. Today s Topics

User Interfaces. Lecture 15. Application Programming on Mac OS. Hamza Bennani September 4, 2018

Assignment III: Graphing Calculator

Navigation and Segues

Lesson 1: Hello ios! 1

Naviga&on and Tab Bar Controllers and Table View

My First iphone App. 1. Tutorial Overview

Building Mapping Apps for ios With Swift

Learn to make desktop LE

Lecture 8 Demo Code: Cassini Multithreading

My First Cocoa Program

ITP 342 Mobile App Dev. Connections

ITP 342 Mobile App Dev. Interface Components

CSC 581: Mobile App Development Spring 2019

imate: ios Application

ITP 342 Mobile App Dev. Fundamentals

Running Code on an ios Device. Appendix. The ios Developer Program

Learn to make ios apps

Assignment III: Graphing Calculator

QUIZ. What is wrong with this code that uses default arguments?

SAMPLE CHAPTER. Brendan G. Lim Martin Conte Mac Donell MANNING

CSE 438: Mobile Application Development Lab 2: Virtual Pet App

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Fall Stanford CS193p Fall 2010

Tables. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Rules and syntax for inheritance. The boring stuff

Assignment IV: Smashtag Mentions

The MVC Design Pattern

S A M P L E C H A P T E R

WINDOWS 8.X SIG SEPTEMBER 22, 2014

Xcode 4 Cookbook. Steven F. Daniel. Chapter No. 2 "User Interfaces Creating the UI"

My First iphone App (for Xcode version 6.4)

ITP 342 Mobile App Development. Model View Controller

Transcription:

Building GUIs with UIKit Kevin Cathey

Building GUIs with UIKit acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

UIKit

UIKit A framework providing many common classes for user interface design.

UIKit A framework providing many common classes for user interface design. Any user interface framework needs to: Present data to the user. Respond to user input.

UIKit A framework providing many common classes for user interface design. Any user interface framework needs to: Present data to the user. Respond to user input. It s all about events.

UIKit

UIKit How UIKit accomplishes this: Defines objects. Defines how they behave. Defines how they interact.

UIKit How UIKit accomplishes this: Defines objects. Defines how they behave. Defines how they interact. All classes in UIKit start with UI.

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

MVC Motivation

MVC Motivation Remember, we have to:

MVC Motivation Remember, we have to: Present data to the user.

MVC Motivation Remember, we have to: Present data to the user. Respond to user input.

MVC Motivation Remember, we have to: Present data to the user. Respond to user input. How do we create a system that does the above and:

MVC Motivation Remember, we have to: Present data to the user. Respond to user input. How do we create a system that does the above and: Allows data code to be modular (work with any view)?

MVC Motivation Remember, we have to: Present data to the user. Respond to user input. How do we create a system that does the above and: Allows data code to be modular (work with any view)? Allows view code to be modular (work with any data model)?

Model - View - Controller City Cupertino Glendale Los Angeles Palo Alto San Diego San Francisco Santa Clara Santa Monica Population 53,293 196,979 3,834,340 58,246 1,266,731 764,976 109,756 87,212 Model

Model - View - Controller City Cupertino Glendale Los Angeles Palo Alto San Diego San Francisco Santa Clara Santa Monica Population 53,293 196,979 3,834,340 58,246 1,266,731 764,976 109,756 87,212 Model View

Model - View - Controller City Cupertino Glendale Los Angeles Palo Alto San Diego San Francisco Santa Clara Santa Monica Population 53,293 196,979 3,834,340 58,246 1,266,731 764,976 109,756 87,212 Model View

Model - View - Controller City Cupertino Glendale Los Angeles Palo Alto San Diego San Francisco Santa Clara Santa Monica Population 53,293 196,979 3,834,340 58,246 1,266,731 764,976 109,756 87,212 Model Controller View

The Controller

The Controller Knows how to talk to the model and the view.

The Controller Knows how to talk to the model and the view. Passes data from the model to the view as needed.

The Controller Knows how to talk to the model and the view. Passes data from the model to the view as needed. Updates the model when the view changes.

The Controller Knows how to talk to the model and the view. Passes data from the model to the view as needed. Updates the model when the view changes. Usually specific to the model and the view.

Controllers Comparative number of controllers Data Models Views Controllers

Controllers Comparative number of controllers Data Models Views Controllers

Controllers Comparative number of controllers Data Models Views Controllers

Controllers Comparative number of controllers Data Models Views Controllers

The Controller

The Controller Can handle interactions between views (one controller can manage many views).

The Controller Can handle interactions between views (one controller can manage many views). Controller has a to-many relationship with views (but usually one-to-one).

The Controller Can handle interactions between views (one controller can manage many views). Controller has a to-many relationship with views (but usually one-to-one). Views have a one-to-one relationship with a view controller.

UIKit and MVC

UIKit and MVC Data Models Foundation Classes Custom Classes

UIKit and MVC Data Models Foundation Classes Custom Classes Views UIView UIButton UITableView UITabBar UISlider

UIKit and MVC Data Models Foundation Classes Custom Classes Views UIView UIButton UITableView UITabBar UISlider Controllers UIViewController UINavigationController UITabBarController UITableViewController

How do I make them all?

How do I make them all? Data Models Write all in code. We already looked at this.

How do I make them all? Data Models Write all in code. We already looked at this. Views Create in Interface Builder. Save as a Nib file.

How do I make them all? Data Models Write all in code. We already looked at this. Views Create in Interface Builder. Save as a Nib file. Controllers Setup basics in Interface Builder. Write all the behaviors and interaction with data in code.

As you create your graphical user interfaces, you must follow the Human Interface Guidelines (the HIG )

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Interface Builder An application that allows you to build GUIs with drag and drop and WYSIWYG. Build object graph by dragging out objects from the library. Customize objects. Setup interactions between code and UI with connections. Save everything to a Nib file.

Nib Files After you create your object graph in IB, you freeze it. This process is called archiving (remember NSCoder protocol?) When your application runs, it unfreezes or unarchives the object graph.

Nib Files An example archiving UISwitch value = on frame = ((x,y), (w,h))

Nib Files An example archiving Hit Save UISwitch value = on frame = ((x,y), (w,h))

Nib Files An example archiving Hit Save UISwitch value = on frame = ((x,y), (w,h)) encodewithcoder:

Nib Files An example archiving UISwitch value = on frame = ((x,y), (w,h)) Hit Save encodewithcoder: 010111001 010010101

Nib Files An example unarchiving

Nib Files An example unarchiving 010111001 010010101

Nib Files An example unarchiving 010111001 010010101 initwithcoder:

Nib Files An example unarchiving 010111001 010010101 initwithcoder: UISwitch value = on frame = ((x,y), (w,h))

Actually it s more complicated The develop time XIB file

Actually it s more complicated The develop time XIB file Hit Save <object /> encodewithcoder: Develop Time

Actually it s more complicated The develop time XIB file Hit Save <object /> encodewithcoder: 01101010111 encodewithcoder: Build Time Develop Time

Actually it s more complicated The develop time XIB file Hit Save <object /> encodewithcoder: 01101010111 encodewithcoder: 01101010111 initwithcoder: Runtime Build Time Develop Time

The XIB File

The XIB File Like a Nib file, but plain-text.

The XIB File Like a Nib file, but plain-text. SCM diffable.

The XIB File Like a Nib file, but plain-text. SCM diffable. Also contains metadata specific to Interface Builder.

The XIB File Like a Nib file, but plain-text. SCM diffable. Also contains metadata specific to Interface Builder. Flattened into binary at compile-time.

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Connections

Connections How we connect code and UI.

Connections How we connect code and UI. Outlets Connecting code to UI. Instance variables in a class. Get filled in at runtime.

Connections How we connect code and UI. Outlets Connecting code to UI. Instance variables in a class. Get filled in at runtime. Actions Connection UI to code. Method on a class called by UI.

Outlets Use IBOutlet keyword on instance variable or property. Flag for Interface Builder s parser.

Outlets Use IBOutlet keyword on instance variable or property. Flag for Interface Builder s parser. Definition of an outlet: #define IBOutlet

Outlets Use IBOutlet keyword on instance variable or property. Flag for Interface Builder s parser. Definition of an outlet: #define IBOutlet Declaring outlet on instance variable: @interface Foo : Bar { IBOutlet UIView *myview; } @end

Outlets Use IBOutlet keyword on instance variable or property. Flag for Interface Builder s parser. Definition of an outlet: #define IBOutlet Declaring outlet on instance variable: @interface Foo : Bar { IBOutlet UIView *myview; } @end Declaring outlet on property: @property(nonatomic, retain) IBOutlet UIView *myview;

Outlets Use IBOutlet keyword on instance variable or property. Flag for Interface Builder s parser. Definition of an outlet: #define IBOutlet Declaring outlet on instance variable: @interface Foo : Bar { IBOutlet UIView *myview; } @end Declaring outlet on property: @property(nonatomic, retain) IBOutlet UIView *myview; Very important to set retain attribute

Actions Use IBAction as return type for method. One argument of type id (this is who sent the action). Flag for Interface Builder s parser.

Actions Use IBAction as return type for method. One argument of type id (this is who sent the action). Flag for Interface Builder s parser. Definition of an action: #define IBAction void

Actions Use IBAction as return type for method. One argument of type id (this is who sent the action). Flag for Interface Builder s parser. Definition of an action: #define IBAction void Declaring an action: @interface Foo : Bar { } - (IBAction)nameOfAction:(id)sender; @end

Connecting outlets & actions in IB After you ve defined actions and outlets in header, do either:

Connecting outlets & actions in IB After you ve defined actions and outlets in header, do either: Old-school method Hold control, drag from source to destination

Connecting outlets & actions in IB After you ve defined actions and outlets in header, do either: Old-school method Hold control, drag from source to destination Using connection display Right-click on object. Then for outlet/action, drag to other object.

Demo Hello World

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

UIViewController You will be creating many subclasses of this. Has view outlet which is the view it principally manages. Can load view from another Nib file using Nib Name property in Interface Builder (or nibname method in code). Common methods to override in subclasses:

UIViewController You will be creating many subclasses of this. Has view outlet which is the view it principally manages. Can load view from another Nib file using Nib Name property in Interface Builder (or nibname method in code). Common methods to override in subclasses: Responding to memory warnings: - (void)didreceivememorywarning;

UIViewController You will be creating many subclasses of this. Has view outlet which is the view it principally manages. Can load view from another Nib file using Nib Name property in Interface Builder (or nibname method in code). Common methods to override in subclasses: Responding to memory warnings: - (void)didreceivememorywarning; Allowing autorotation: // To always allow autorotation... - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { return YES; }

UIViewController You will be creating many subclasses of this. Has view outlet which is the view it principally manages. Can load view from another Nib file using Nib Name property in Interface Builder (or nibname method in code). Common methods to override in subclasses: Responding to memory warnings: - (void)didreceivememorywarning; Allowing autorotation: // To always allow autorotation... - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { return YES; } Doing final setup of view after it loads from Nib: - (void)viewdidload;

UITabBarController Has tabs, each tab being a view controller. Don t subclass. For each tab (view controller), load its UI from external Nib file otherwise all views instantiated immediately.

UINavigationController

UINavigationController Has stack of view controllers.

UINavigationController Has stack of view controllers. To move right, push a view controller.

UINavigationController Has stack of view controllers. To move right, push a view controller. To move left, pop a view controller.

UINavigationController Has stack of view controllers. To move right, push a view controller. To move left, pop a view controller. Don t subclass.

UINavigationController Has stack of view controllers. To move right, push a view controller. To move left, pop a view controller. Don t subclass. Usually root controller or contained by a tab bar controller.

UINavigationController Has stack of view controllers. To move right, push a view controller. To move left, pop a view controller. Don t subclass. Usually root controller or contained by a tab bar controller. Pushing a view controller: [mynavcontroller pushviewcontroller:nextcontroller animated:yes];

UINavigationController Has stack of view controllers. To move right, push a view controller. To move left, pop a view controller. Don t subclass. Usually root controller or contained by a tab bar controller. Pushing a view controller: [mynavcontroller pushviewcontroller:nextcontroller animated:yes]; Popping a view controller (usually don t have to call this): [mynavcontroller popviewcontrolleranimated:yes];

UITableViewController Manages as a table view s data source and delegate. Subclass and override at least these methods:

UITableViewController Manages as a table view s data source and delegate. Subclass and override at least these methods: Number of rows in a given table view section: - (NSInteger)tableView:(UITableView *)tableview numberofrowsinsection:(nsinteger)section;

UITableViewController Manages as a table view s data source and delegate. Subclass and override at least these methods: Number of rows in a given table view section: - (NSInteger)tableView:(UITableView *)tableview numberofrowsinsection:(nsinteger)section; Provide a row of content: - (NSInteger)tableView:(UITableView *)tableview numberofrowsinsection:(nsinteger)section;

UIView

UIView Represents what you actually see on screen.

UIView Represents what you actually see on screen. This is where the drawing occurs.

UIView Represents what you actually see on screen. This is where the drawing occurs. The first to receive user events if the view doesn t need the event, it sends it to its view controller.

UIView Represents what you actually see on screen. This is where the drawing occurs. The first to receive user events if the view doesn t need the event, it sends it to its view controller. Subclass only for customization of one of those two roles.

UIView

UIView Views have a superview (except the root view, also called the window) and subviews.

UIView Views have a superview (except the root view, also called the window) and subviews. Drawing is clipped to its superview.

UIView Views have a superview (except the root view, also called the window) and subviews. Drawing is clipped to its superview. Size and location of a view is called its frame.

UIView Views have a superview (except the root view, also called the window) and subviews. Drawing is clipped to its superview. Size and location of a view is called its frame. The bounds of a view are usually the same as its frame, except with the location always at (0,0).

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Building GUIs with UIKit What is UIKit? Model-view-controller What really is a Nib file? Connecting code to UI Tour of common UIKit classes acm.uiuc.edu/macwarriors/devphone

Q&A About These Slides If you need to reference the content of this presentation, these slides will be posted on our website, listed below: acm.uiuc.edu/macwarriors/devphone