Top Banner
IOS ESSENTIALS Lecture 04 Jonathan R. Engelsma, Ph.D.
20
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

IOS ESSENTIALSLecture 04

Jonathan R. Engelsma, Ph.D.

Page 2: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

TOPICS

• Model / View / Controller

• Understanding ViewControllers and their life cycle.

• Overview of commonly used iOS ViewControllers

Page 3: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Our iOS code is broken up into 3 different components(Inspired by Paul Hegarty’s very excellent MVC lecture.)

Page 4: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Controller

View

The MODEL is the data our app produces/consumes.

Model

Page 5: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

The VIEW is what the user sees and interacts with on screen.

View

Page 6: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model View

The CONTROLLER manages the model and the view.

Controller

Page 7: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Controller can manipulate the model directly.

Page 8: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Controller can manipulate the view directly.

Takes place via an “outlet”

Page 9: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Model / View should NEVER talk directly to each other!

Page 10: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Views can sort of talk to controller, but only in a very controlled manner!

Controller defines an action.

View is wiredup to call action.

Page 11: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

MODEL/VIEW/CONTROLLER

Model

Controller

View

Controller serves as the View’s delegate and data source via Protocols

DelegateData Source

Page 12: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

GREETING DEMO

DEMO!!

Page 13: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

VIEW CONTROLLERS• View controllers manage a screen’s view hierarchy and the

segues between view controllers.

• The “glue” between views and models in MVC.

• View controllers:

• initialize and setup models

• populate the view hierarchy with views

• coordinate with the view hierarchy (delegate)

• format data for the views (data source)

Page 14: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

VIEW CONTROLLER LIFECYCLE

• Recall the methods generated when we created our first app:override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.configureView() }

override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }

• These are methods that help us coordinate with the controller’s lifecycle.

Page 15: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

VIEW CONTROLLER LIFE CYCLE

• Understanding the view controller life cycle allows us to properly manage the controller’s models and views.

• Whenever a view controller’s view property is accessed a chain of events is triggered.

https://developer.apple.com/library/IOS/featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html

Page 16: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

View property Accessed

Viewexists? loadView

Return view

loadViewoverriden?

Run loadView

Storyboard?

Load from storyboard

EmptyView

viewDidLoad

YY Y

N

N N

Page 17: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

VIEW CONTROLLER METHODS

Method Name DescriptionviewDidLoad View has finished loading.

viewWillAppear View is about to appear.viewDidAppear View just appeared.

viewWillDisappear View is about to disappear.viewDidDisappear View just disappeared

didRecieveMemoryWarning Low memory conditions detected.

Page 18: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

UITabBarController UICollectionViewController UITableViewController

Page 19: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

UINavigationController

Page 20: iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 04)

LIFECYCLE & STOPWATCH DEMOS

DEMO!!