the screen and handles the drawing and touch events in that region. • Every application has at least one view (the window) for presenting it’s content. • A view can also act as a parent for other views and coordinate the placement and sizing of those views. • Examples: Buttons, Navigation Bars, Alerts, Table View Cells, etc...
view. • A view controller owns it’s view. It takes care of all user actions, animations, updating the view, etc... • Just like Views, Controllers can act as parents of other Controllers. V M C
hierarchical content. • You can push/pop view controllers into/from the Navigation Controller. • Each time you add a view controller to the hierarchy the Navigation Controller becomes it’s parent. V M C
(each controller has a root view, remember?). • Usually you subclass it to add your custom behavior. • By default it is the delegate and datasource of it’s collection view. V M C
object. • The delegating object sends a message to it’s delegate telling it some event is about to happen and asks for some response. • Delegation is a means for injecting specific behavior in the workings of a framework class — without having to subclass it. V M C
of being delegated control of the UI, it is delegated control of the data. • Responsible for managing the memory of the model objects they give to the delegating view. V M C
out your app screens and transitions • Trees of view controllers in a serialized form • Storyboards = Scenes (VCs) + Segues (transitions) • Good for a conceptual overview of the app • Bad for apps with lots of VCs or iPad apps (HUGE views...) • Limitations: Storyboards < XIBs < Code
0; int i = 0; int i = 0; float f = 0; float f = 0; double d = 0; double d = 0; BOOL b = YES; // NO boolean b = true; // false char c = ‘c’; char c = ‘c’; NSObject *o = [[NSObject alloc] init]; Object o = new Object(); NSString *s = @”string”; String s = “string”;
call • Interpreted in runtime: objects decide if they respond to messages • self = this object (can message self) • super = base (parent) object (can message super)
setters and getters automatically (it was not always like this) • Atomic by default! (use nonatomic to remove lock) @property (nonatomic, copy) NSString *myProperty;
an expected behaviour) • Messages and properties can be mandatory or optional • Used in the delegate pattern: “will ask somebody (the delegate) something” Protocols
• Add new messages without recompile! • Warning: existing messages can be “replaced”. Category messages take precedence. • Similar to .NETs extension methods
init]; • Reference count: keep track of the number of instances. If 0 deallocate object • ARC does retain/release for you automatically. • References: strong (retain), weak, copy (new immutable object)
passed around like data • Key to lots of ObjC features: collection enumeration, Grand Central Dispatch (threads), animations • Explicit or inline definition • Context variable must be marked with __block if changed within block