代写 Announcements

Announcements
• Lab 1 due on Wednesday by 11:59 PM
– Email it to cse438ta@gmail.com
– All labs must run on the iPhone XR
• Previously I mistakenly mentioned they needed to run on the iPhone XS
• We will hold Studio 2 on Wednesday – Along with additional labs on Thursday
1E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 1
Today􏰀s Topics
• Views Introduction • Auto Layout Demo • MVC
• Lab 2
• MVC Demo
2E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 2

Views
3E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 3
View Fundamentals
• Rectangular area on screen
• Draws content
• Handles events
• Subclass of UIResponder (event handling class)
• Views arranged hierarchically
– every view has one superview
– every view has zero or more subviews
4E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 4

View Hierarchy – UIWindow
• Views live inside of a window
• UIWindow is actually just a view
– adds some additional functionality specific to top
level view
• One UIWindow for an iOS app
– Contains the entire view hierarchy
– Set up by default in Xcode template project
5E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 5
UIView Coordinate System
• Origin in upper left corner • y axis grows downwards
• Units are points, not pixels
– Points are units of coordinate system
– Pixels are min size unit of drawing
– Typically 2 pixels per point +y • var ContentScaleFactor
+x
0,0
6E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 6

Lab 2 Preview
7E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 7
Auto Layout Demo
8E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 8

View Controllers
9E- CxtSeEn4s3i8bl–eMNobeitlewAoprpkliincgatiPonlaDtefovermlopment 9
UIViewController
• Basic building block
• Manages a screenful of content
• Subclass to add your application logic
View Controller
10E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 10

Model, View, Controller
11E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinlicgatPiolnatDfoevrmelopment 11
Model, View, Controller
Controller
Model
View
12E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 12

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
13E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 13
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
14E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 14

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
15E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 15
Model, View, Controller
Controller
Model
View
16E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 16

Why Model-View-Controller?
• Separating responsibilities also leads to reusability
• By minimizing dependencies, you can take a model or view class you’ve already written and use it elsewhere
• Think of ways to write fewer lines of code
17E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 17
Model, View, Controller
Controller
outlets actions
View
Model Object
18E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 18

MVC Demo
19E-xCteSnEs4i3b8le– MNoebtiwleoArpkpinligcatPiolantDfoevrmelopment 19