zoukankan      html  css  js  c++  java
  • iOS加载程序视图的方式

    The UIViewController class provides built-in support for loading a view controller’s views whenever they are needed. Specifically, views are automatically loaded when the view property is accessed. There are a few ways you can implement your app to load these views:

    第一种:使用故事板加载

    • 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.

    第二种:使用nib文件加载

    • 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.

    总结

    All of these techniques have the same end result, which is to create the appropriate set of views and expose them through the view property.

    附:

  • 相关阅读:
    命令式语言和声明式语言对比——JavaScript实现快速排序为例
    merge sort 的javascript实现
    快速排序算法的简短描述
    Hadoop 2.x 版本的单机模式安装
    数据分析招聘网招聘信息分析报告
    使用PROC TRANSPOSE过程步对数据集进行转置时如何保持日期变量的时间顺序
    饼图微创意
    我的微博关键字
    QQ群成员发言次数统计(词云制作)
    在SAS数据步中执行过程步的简单示例
  • 原文地址:https://www.cnblogs.com/zhanggui/p/4734634.html
Copyright © 2011-2022 走看看