zoukankan      html  css  js  c++  java
  • UIViewController三种不同的初始化view的方式

    • You can specify the views for a view controller using a Storyboard created in Interface Builder. A storyboard contains preconfigured view controllers and their associated views and is the preferred way to develop your app's€™s user interface. A key advantage of storyboards is that they can express relationships between different view controllers in your app. For example, you can state that one view controller'€™s contents are contained inside another view controller or that a view controller is displayed as a transition (known as a segue) from another view controller . By allowing you to see the relationships between view controllers, storyboards make it easier to understand your app'€™s behavior at a glance.

      At runtime, the view controller uses the storyboard to automatically instantiate and configure its views. Often, the view controller itself is automatically created by segues defined in the storyboard. When you define a view controller'€™s contents using a storyboard, you never directly allocate and initialize the view controller object. Instead, when you need to programmatically instantiate the view controller, you do so by calling the instantiateViewControllerWithIdentifier: method on a UIStoryboard object.

    • You can specify the views for a view controller using a nib file, also created in Interface Builder. Like a storyboard, a nib file allows you to create and configure a set of views. However, you cannot easily create or see the relationships between view controllers using nib files as you can when using storyboards.

      To initialize your view controller object using a nib, you use the initWithNibName:bundle: method to specify the nib file used by the view controller. Then, when the view controller needs to load its views, it automatically creates and configures the views using the information stored in the nib file.

    • If you cannot define your views in a storyboard or a nib file, override the loadView method to manually instantiate a view hierarchy and assign it to the view property.

    IMPORTANT

    A view controller is the sole owner of its view and any subviews it creates. It is responsible for creating those views and for relinquishing ownership of them at the appropriate times such as when the view controller itself is released. If you use a storyboard or a nib file to store your view objects, each view controller object automatically gets its own copy of these views when the view controller asks for them. However, if you create your views manually, you should never use the same view objects with multiple view controllers.

  • 相关阅读:
    Netty源码分析第4章(pipeline)---->第5节: 传播outbound事件
    Netty源码分析第4章(pipeline)---->第4节: 传播inbound事件
    Google地图路线规划
    bootstrap Table 中给某一特定值设置table选中
    枚举类型定义
    日期格式转换 java 2016-09-03T00:00:00.000+08:00
    String字符串针对常量池的优化
    【转】MySQL性能优化的最佳21条经验
    【转】 jquery遍历json数组方法
    如何设置tomcat定时自动重启
  • 原文地址:https://www.cnblogs.com/wangnan1979/p/4362518.html
Copyright © 2011-2022 走看看