Lecture 8

Lecture 8 - Stanford CS193p Fall 2011 Developing...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Stanford CS193p Fall 2011 Developing Applications for iOS Fall 2011 Stanford CS193p Stanford CS193p Fall 2011 Today View Controller Lifecycle When your controller hears about things and what you should do about it. Image View Kind of like UILabel for images (as opposed to text). Web View Complete browser in a view. Scroll View Provides a moving viewport on a rectangular area that has views (the scroll views subviews) in it. Demo (time permitting) Dr. Pills Website View Controller Imaginarium Stanford CS193p Fall 2011 View Controller Lifecycle View Controllers have a Lifecycle A sequence of messages is sent to them as they progress through it Why does this matter? You very commonly override these methods to do certain work Weve talked about the rst part of the lifecycle Creation This is done mostly either via a segue or storyboards instantiateViewControllerWithIdentifer: . Because of this, we rarely (never?) override UIViewController s designated initializer in iOS 5. awakeFromNib is an option, but we rarely do that either. There are better methods to initialize in ... Stanford CS193p Fall 2011 View Controller After instantiation and outlet-setting, viewDidLoad is called- (void)viewDidLoad; This is an exceptionally good place to put a lot of setup code. But be careful because the geometry of your view (its bounds ) is not set yet! If you need to initialize something based on the geometry of the view, use the next method ... Just before the view appears on screen, you get notied- (void)viewWillAppear:(BOOL)animated; When this is called, your bounds has been set (via your frame by your superview or some such). Your view will probably only get loaded once, but it might appear and disappear a lot. So dont put something in this method that really wants to be in viewDidLoad . Otherwise, you might be doing something over and over unnecessarily. Use this to optimize performance by waiting until this method (i.e. just before view appears) to kick off an expensive operation (might have to put up a spinning loading icon though). Summary: this method is for geometry-related initialization and lazy execution for performance. Stanford CS193p Fall 2011 View Controller And you get notied when you will dis appear off screen too This is where you put remember whats going on and cleanup code.- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // call super in all the viewWill/Did ... methods // lets be nice to the user and remember the scroll position they were at ... [self rememberScrollPosition]; // well have to implement this, of course // do some other clean up now that weve been removed from the screen [self saveDataToPermanentStore]; // maybe do in did instead?...
View Full Document

This note was uploaded on 01/25/2012 for the course CS 193P taught by Professor Evandoll during the Fall '09 term at Stanford.

Page1 / 47

Lecture 8 - Stanford CS193p Fall 2011 Developing...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online