Stanford_iOS_L06_Multiple MVCs...

^+I ReIdent
http://www.cocoachina.com/ios/20141224/10752.html

Segue

Stanford_iOS_L06_Multiple MVCs..._第1张图片
Paste_Image.png
  if let navcon = destinationvc as? UINavigationController {
        destinationvc = navcon.visibleViewController ?? destinationvc
    }
//the botttom navcon , it`s visibleView is Face


ViewController Lifecycle

What then?

  1. Preparation if being segued to.
  1. Outlet Setting.
  2. Appearing and disappearing
  3. Geometry changes.
  4. Low-memory situations.

After instantiation and outlet-setting, viewDidLoad is called

this is an exceptionally good place to put a lot of setup code
Its better than an init because your outlets are all set up by the time this is called.

   override func viewDidLoad(){ 
        super.viewDidLoad()  // always let super have a chance in lifecycle methods
        //do some setup of my MVC
    }

One thing u may well want to do here is update ur UI from ur Model.
Because now u know all of ur outlets are set

BUT, geometry of ur View is not set yet.

Just before ur view appears on screen, u get notified

 func viewWillappear( animated: Bool) // animated is whether u are appearing 
Stanford_iOS_L06_Multiple MVCs..._第2张图片
Paste_Image.png

And u get notified when u will disappear off screen too

This is where u put "remember what`s going on " and cleanup code.

 override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated) // call super in all the ViewWill/Did methods
//do some cleanup now that we`ve been removed form the screen
// but be careful not to do anything time-consuming here, or app will be sluggish
// maybe even kick off a thread to do stuff here(again, we`ll cover threads later
}

There is a "did" version of this too

  func viewDidDisappear(animated: Bool)

Geometry changed?

Stanford_iOS_L06_Multiple MVCs..._第3张图片
=W=.png

Autorotation

Stanford_iOS_L06_Multiple MVCs..._第4张图片
ddd

Summary

Stanford_iOS_L06_Multiple MVCs..._第5张图片

Demo

你可能感兴趣的:(Stanford_iOS_L06_Multiple MVCs...)