iOS Programming: The Big Nerd Ranch Guide (4th Edition) 阅读笔记-关于 View Controllers及其生命周期

  • View Controller
    • View controller 管理一个 view hierarchy ,它负责创建 view 对象以形成 hierarchy、处理该 hierarchy 中有关于 view 的事件、并且将该 hierarchy 添加到 window 中。
    • View controller UIView *view 属性指向一个 view ,该 view 是该 controller view hierarchy 的根。当该 view 被设置为 window subview 时,整个 view controller view hierarchy 也被加入到 window

  • View controller view 直到它需要呈现在屏幕上才会被创建(惰性初始化以节约内存和提高性能)
    • View controller 创建 view 的两种方式
      • 编写代码覆写 controller loadView 方法
        • view controller 创建时,它的 view nil,当它需要 view 且此时 view nil 时,view controller 就会被发送 loadView 消息。
      • Interface Builder 中加载 NIB 文件
  • 最后将 view controller 设置为 window rootViewController 就完成了整个过程

 

  • NIB 的加载过程

 

  • Interacting With View Controllers and Their Views
    • Application:didFinishLaunchingWithOptions: 用于初始化并设置 application root view

该方法在应用启动的时候会被回调。即使应用切换,也不会被再次回调。

  • initWithNibName:bundle: 该方法是 UIViewController designated initializer

view controller 实例被创建时,该方法会被回调。如果创建同一个 view controller class 的多个实例,该方法每次都会被回调。

  • loadView: 覆写该方法以通过代码方式为该 view controller 创建 view
  • viewDidLoad 该方法会在 view view controller 被创建后回调,它可以用来配置用 NIB 文件来加载的 view
  • viewWillAppear: 可以覆写该方法以配置用NIB文件来加载的 view

该方法和 viewDidAppear 在每次 view controller 呈现在屏幕上的时候都会被回调。

  • viewWillDisappear: / viewDidDisappear: 这两个方法在 view controller 每次离开屏幕时都会被回调。

(区别于 viewDidLoad 只会在创建时被回调)

 

  • View Controller 的生命周期

来自:http://blog.csdn.net/ryantang03/article/details/8264072

 

View的加载过程

 

 

ViewView Controller的关系

 

View的卸载过程

 

 

  • ViewController的生命周期中各方法执行流程如下:

init—>loadView—>viewDidLoad—>viewWillApper—>viewDidApper—>viewWillDisapper—>viewDidDisapper—>viewWillUnload->viewDidUnload—>dealloc

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
About the Book iPhone Programming: The Big Nerd Ranch Guide is based on Big Nerd Ranch's Beginning iPhone Bootcamp and takes the same approach as our tried and true classes: learning the necessary programming concepts by actually building appllications. About the Authors Joe Conway is the senior iPhone instructor at the Big Nerd Ranch and has been consulting on the iPhone platform since its creation. A University of Wisconsin graduate, he has been writing Objective-C and Cocoa code since the dawn of OS X. Joe wrote the materials for the exceptionally popular Big Nerd Ranch iPhone Bootcamp, which eventually evolved into this book. Aaron Hillegass is the founder of Big Nerd Ranch. A former employee at NeXT and Apple, he has twenty years experience with Objective-C and Cocoa. Aaron wrote "Cocoa Programming for Mac OS X," the standard text on developing Mac applications. Updated and expanded to cover iOS 7 and Xcode 5, iOS Programming: The Big Nerd Ranch Guide leads you through the essential concepts, tools, and techniques for developing iOS applications. After completing this book, you will have the know-how and the confidence you need to tackle iOS projects of your own. Based on Big Nerd Ranch's popular iOS Bootcamp course and its well-tested materials and methodology, this bestselling guide teaches iOS concepts and coding in tandem. The result is instruction that is relevant and useful. Throughout the book, the authors explain what's important and share their insights into the larger context of the iOS platform. You get a real understanding of how iOS development works, the many features that are available, and when and where to apply what you've learned. Here are some of the topics covered: Xcode 5, Instruments, and Storyboards Building interfaces using the iOS 7 aesthetic ARC and strong and weak references Handling touch events and gestures Toolbars, navigation controllers, and split view controllers Using Auto Layout to scale user interfaces Using Dynamic Type

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值