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

Similar documents
Mobile Application Development

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

ITP 342 Mobile App Dev. Delegates

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

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

Building GUIs with UIKit. Kevin Cathey

Introductory ios Development

User Experience: Windows & Views

Event Delivery: The Responder Chain

ITP 342 Mobile App Dev. Connections

ITP 342 Mobile App Dev. Table Views

Xamarin for C# Developers

ITP 342 Mobile App Dev. Interface Builder in Xcode

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

ITP 342 Mobile App Dev. Connections

Assignment III: Graphing Calculator

ITP 342 Mobile App Dev. Table Views

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

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

View Controllers CPRE 388

Assignment III: Graphing Calculator

Quick Interaction Techniques for watchos

Duration 5 days (For basic crowd 5+3days needed)

Navigation and Segues

Introduction to WatchKit. CS193W - Spring Lecture 1

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

App. Chapter 19 App. App (ViewController) App. Single View Application Single View Application View. (View Controller)

ITP 342 Mobile App Development. Model View Controller

Designing iphone Applications

CS193P - Lecture 7. iphone Application Development. Navigation & Tab Bar Controllers

ios Developer s Guide Version 1.0

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

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

View Controller Advancements for ios8

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

Assignment IV: Smashtag Mentions

Assignment III: Graphing Calculator

Building User Interface for Android Mobile Applications II

ITP 342 Mobile App Dev. Interface Components

Lecture 8 Demo Code: Cassini Multithreading

ITP 342 Mobile App Development. Model View Controller

MS_40541 Build Native Cross-Platform Mobile Apps with a Shared C# Business Logic for ios, Android, and UWP in C#.NET with Xamarin and Visual Studio

Mobile Application Development

NATIVE APP INTERCEPTS on ios & ANDROID

Mobile Application Programming. Messaging and Delegation

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

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

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

Why Model-View-Controller?

Announcements. Today s Topics

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

Assignment III: Graphing Calculator

Praktikum Entwicklung von Mediensystemen mit

ios 9 SDK Development

A Mad Libs app that you will navigate through 3 UIViewControllers to add text that will be shown in a story on the fourth UIViewController.

Mobile Application Programing: ios. Messaging

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

Building Mapping Apps for ios With Swift

Enhancing your apps for the next dimension of touch

CSC 581: Mobile App Development Spring 2018

ITP 342 Mobile App Dev. Interface Fun

ADVANCED M A. Learn SiriKit, imessage apps, rich notifications, and more. with real-world projects HACKING WITH SWIFT COMPLETE TUTORIAL COURSE

Model-View-Controller Architecture

Implementing UI Designs in Interface Builder

NaviGate Prepared App: Using Respond

Lesson 1: Hello ios! 1

Creating Content with iad JS

HACKING WITH SWIFT. Practical. ios 10 COMPLETE TUTORIAL COURSE. Learn to develop apps. for ios 10 by building MP. real-world projects E S

Apple Watch Docs. Release 0.1. Michael Hahn

Medallia Mobile 2 App

Mobile Development - Lab 2

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

Building an Application

New UIKit Support for International User Interfaces

CS 147 Let s Do This! Assignment 6 Report

INTRODUCTION TO ARCHITECTING YOUR IOS APP

ios Application Development Course Details

ITP 342 Mobile App Dev. Web View

News- ipad: ios(swift) Application

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

Object-Oriented Programming in Objective-C

Document Version Date: 1st March, 2015

Storyboards and Controllers on OS X

Architecting ios Project. Massimo Oliviero

IPhone Application of Carleton University. Carleton University Computer Science Honors Project Report

View Controller Lifecycle

ios vs Android By: Group 2

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

BRIGHTSIGN APP USER GUIDE

let w = UIWindow(frame: UIScreen.mainScreen().bounds)

Lab Guide. Service Portal and Mobile. Patrick Wilson & Will Lisac. Default Login / Password: admin / Knowledge17. itil / Knowledge17

ios Mobile Development

HKUST. CSIT 6910A Report. iband - Musical Instrument App on Mobile Devices. Student: QIAN Li. Supervisor: Prof. David Rossiter

Registering for the Apple Developer Program

Minds-on: Android. Session 2

The MVC Design Pattern

ios Mobile Development

Programming in Android. Nick Bopp

ios 9 Day by Day Also by shinobicontrols This version was published Scott Logic Ltd

CS193P - Lecture 11. iphone Application Development. Text Input Presenting Content Modally

Transcription:

MVC & Onwards CS 442: Mobile App Development Michael Saelee

Agenda - Recap: view-controller communication - Delegation as a general pattern - Observer pattern - Controller responsibilities & MVC - Multiple scenes & controllers

Simple view-controller communication: - target-action (view push) - designate method as @IBAction - outlet (controller push/pull) - designate attribute as @IBOutlet

For complex views, view defines API for controller to adopt: delegation protocol - enables view push & pull - enables/simplifies reuse of complex UI widgets

- but delegation isn t just used for viewcontroller communication - same mechanism used for relaying app lifecycle notifications to our custom code - App UIApplicationDelegate - Recall high-level app event callbacks

from Apple s ios App Programming Guide

from Apple s ios App Programming Guide

AppDelegate also receives events that are not handled by views or view controllers low-level touch and motion events functions as catch-all handler

UIApplication AppDelegate Window superview View superview View superview View designated event recipient ViewController ios responder chain

View designated event recipient - two basic ways for an object to be the designated recipient of an event 1. hit-testing for touches 2. assumes first responder status - note: designated recipient doesn t have to be a view (any subclass of UIResponder)

Classes in the view system (from View Controller Programming Guide for ios

sometimes it s handy to broadcast/receive notifications in non-default ways notifications outside our scope notifications that aren t sent by default app-specific notifications

Observer Pattern - any object can register to receive notifications of specific events - One mechanism: notification centers - Enables action at a distance (not necessarily a good thing!)

Delegation embodies the separation of (1) the thing where events happen and (2) the thing that processes events (1) is the view (2) is the view controller

But the list of responsibilities is lopsided. (1) just has to map inputs to high-level actions; e.g., a touch in a table area to cell selection (2) has to (a) map an action to a semantic intent, then (b) actually carry out that intent

(a) is the controller s job, but (b) often requires domain-specific knowledge

to allow for reuse (and modular design) of (b) would like to extricate this from the controller s implementation

Controller View Model

MVC is central to the architecture of virtually all native ios apps, and is found at all levels of the development stack

Turns out the one-controller-per-scene tale is not really accurate often need a controller to manage transitions between separate, per-screen controllers overarching container controllers

Built-in controllers for this!

View controller classes in UIKit (from View Controller Programming Guide for ios

Navigation container controller (from View Controller Programming Guide for ios

Tab bar container controller (from View Controller Programming Guide for ios

Good news: intended for use without subclassing typically drop into Storyboard & customize in code if necessary segues are used as to connect controllers e.g., to pass data (true even without container controllers)

A segue tracks: 1. Source controller 2. Destination controller 3. Segue name (unique in storyboard)

When a segue is triggered: - the destination controller is created - prepareforsegue is called in source - an [animated] transition from source to destination controller takes place

Segues seem magical, but really just add another layer of abstraction on top of what we already have

Controller transition without segue: 1. Event (e.g., button tap) triggers action 2. Action method creates dest controller 3. [Pass data to dest in action method] 4. Use presentviewcontroller to activate dest controller

Controller transition with segue: 1. Event triggers creation of segue object 2. Segue populates its src/dest controllers 3. prepareforsegue called in src controller 4. [Pass data to dest in prepareforsegue]

Controller transition with segue: 5. Segue object s perform is invoked 6. [perform method animates transition] 7. perform calls presentviewcontroller to complete transition

If we use built-in segues, most of this is automatic (i.e., invisible)

Can do away (sometimes) with cumbersome & wordy delegate mechanism

When a segue is triggered: (slight problem) - the destination controller is created - prepareforsegue is called in source - good place to send data to destination

(sometimes we want to return to an existing controller/scene)

Unwind segues let us return to an unwind action in a previous controller

/* Sample unwind segue action */ - (IBAction)unwindSegue:(UIStoryboardSegue *)segue { ViewController *srccontroller = segue.sourceviewcontroller; /* retrieve data from srccontroller */ } /* note: manually dismissing srccontroller isn t done here! */ Conveniently, segue stores and retains source controller can retrieve data in destination before source goes away

Container controllers

so far, we can create a modal VC relationship but that s not always enough to build/describe a complex app

other typical VC relationships: - hierarchical / drill-down navigation - sibling / parallel tabbed

in both cases, there is some overarching context for the related VCs

navigation bar

tab bar

UINavigationController & UITabBarController = container view controllers

container view controllers track and manage transitions between other view controllers - implement custom transitions - simplify controller management & communication

e.g., UINavigationController

views managed by different VCs on screen simultaneously (previously a no-no)

NavController manages a stack of related view controllers

NavController also exposes an API for managing the navigation & tool bars

UINavigationController Creating Navigation Controllers initwithrootviewcontroller: Accessing Items on the Navigation Stack topviewcontroller property visibleviewcontroller property viewcontrollers property setviewcontrollers:animated: Pushing and Popping Stack Items pushviewcontroller:animated: popviewcontrolleranimated: poptorootviewcontrolleranimated: poptoviewcontroller:animated: UIViewController Getting the Navigation controller navigationcontroller property Configuring a Navigation Interface navigationitem property hidesbottombarwhenpushed property settoolbaritems:animated toolbaritems property UINavigationItem Getting and Setting Properties title property backbarbuttonitem property hidesbackbutton property Customizing Views leftbarbuttonitem property rightbarbuttonitem property