43
These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. Interface Builder & Mac UI Programming Lecture 6

Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Interface Builder & Mac UI Programming

Lecture 6

Page 2: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Model-View-Controller

Page 3: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

The Model

•This is your data model; maintains state

•Has no idea about UI or how the data is presented

•Example: a Fraction class for a fraction calculator app

Page 4: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

The View

•The part the user sees; the UI

•Displays the model

•Does not store data (except maybe caching its state)

Page 5: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

The Controller

•The middleman between the model and view

•Updates the view when the model changes

•Tells the model to update when the user manipulates the view

Page 6: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Model, View, Controller

ModelView

Controller

Page 7: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Model, View, Controller

ModelView

Controller

Page 8: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Model, View, Controller

ModelView

Controller

Page 9: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Model, View, Controller

ModelView

Controller

Page 10: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Demo: Making a UI

Page 11: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Autoresizing Views

•By default, views don't resize or move as its parent view resizes

•Views can set several properties to customize their resizing behavior

•Then Cocoa takes over and computes the appropriate size and location for the view

Page 12: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Page 13: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Page 14: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Anchor to top

Page 15: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Anchor to bottom

Page 16: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Anchor to left

Page 17: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Anchor to right

Page 18: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Flexible width

Page 19: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Struts & Springs

Flexible height

Page 20: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Autolayout

•New (10.7+) system for arranging views

•"Constraint" based system

•Interface Builder automatically turns the blue guidelines it shows into constraints

Page 21: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Benefits

• Reduced need for in-code layout

• Constraints accommodate dynamic content

• Improved in-code layout

• ASCII art, improved layering

• Design flexibility

• Baselines, alignment rect, intrinsic content size

• Localization

• Dynamic content, intrinsic content size

• Expressiveness

• Peer to peer relationships, inequalities, priority

Page 22: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Outlets & Actions

•How do we connect our code to the user interface (and vice-versa)?

•Outlets: create references in code to UI controls

•Actions: allow UI controls to send messages to objects

•Control-drag to attach

Page 23: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Outlets

•IBOutlet NSButton* button;

•IBOutlet is completely ignored by the compiler

•It’s simply an indicator for Interface Builder

•Caution! Outlets may not be loaded (connected) until - (void) awakeFromNib

Page 24: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Actions

•- (IBAction) buttonClicked: (NSButton*) sender;

•IBAction is #define’d as void

•The sender argument is required

Page 25: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Target-Action

•Actions can be set manually on controls

•On Mac, controls have one target-action

- (void) setTarget: (id) target;

- (void) setAction: (SEL) action;

Page 26: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Nib Loading

•A nib is not generated code.

•Rather, it is a collection of serialized objects

•Connects outlets & actions automatically

•Then calls - (void) awakeFromNib on each object

Page 27: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Page 28: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Page 29: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Page 30: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Page 31: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Controller

Page 32: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Controller

Get state Update UI

Page 33: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

MVC Example

Model (Person)

- (NSImage*)photo;- (NSString*)name;- (NSString*)email;

Steve [email protected]

View (Address Card)

Controller- (IBAction) emailClicked: (id) sender

Get state Update UI

Page 34: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Demo: Slider

Page 35: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

NSApplication

•Manages the main run loop of your application:

•Waits for events from the mouse, keyboard

•Dispatches events to the relevant objects (of class NSResponder)

•Owner of MainMenu.xib

Page 36: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

NSView

•Superclass for all views in Cocoa

•Position and size in [view frame]

•[view addSubview:] and friends used for programmatic layout

•Often subclassed; we’ll talk about making your own views later

Page 37: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

NSWindow

•Manages window frame

•Views in window are subviews of[window contentView]

Page 38: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

The View Hierarchy

[window contentView]

NSWindow NSView

[contentView subviews]

[box subviews]

Page 39: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

NSControl

•Subclass of NSView

•Concept of value: [control intValue], [control floatValue], stringValue, and so on

•Superclass for text fields, buttons, etc.

Page 40: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Delegation

•Common pattern in Cocoa; avoids need to subclass in simple cases

•Objects notify their delegates when something happens through delegate methods

•Application delegate: start, terminate

•Window delegate: resize, close

Page 41: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Application Life Cycle

•Application starts

•MainMenu.xib loads

•Run loop:

•Wait for event

•Handle event

•Application terminates

Page 42: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Application Life Cycle

•Application starts

•MainMenu.nib loads

•Event loop

•Application terminates

[delegate applicationDidFinishLaunching:notification];

Page 43: Interface Builder & Mac UI Programminginst.eecs.berkeley.edu/~msdosx/sp12/lectures/lecture06.pdf · These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

These slides are licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

Application Life Cycle

•Application starts

•MainMenu.nib loads

•Event loop

•Application terminates

[delegate applicationWillTerminate:notification];