博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS加载程序视图的方式
阅读量:5895 次
发布时间:2019-06-19

本文共 2463 字,大约阅读时间需要 8 分钟。

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'ss 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.

  • 参考自

转载地址:http://ysssx.baihongyu.com/

你可能感兴趣的文章
安卓中如何实现滑动导航
查看>>
Java-金额小数转换成中文大写金额
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
squid.3.2故障整理
查看>>
Ansible Tower安装配置全过程(上)
查看>>
地址与引用
查看>>
十大开源ERP点评 献给深水区的中小企业和CIO们
查看>>
【PHP】创蓝253云通信平台国际短信接口调用demo案例
查看>>
Confluence 6 重要缓存和监控
查看>>
Day 30 shell 编程
查看>>
静态路由和默认路由
查看>>
谈一谈Spring-Mybatis在多数据源配置上的坑
查看>>
2.1 shell语句
查看>>
【精益生产】车间现场管理的八大浪费
查看>>
springMVC国际化
查看>>
变频电源内部的元器件是有着什么样的发挥和作用
查看>>
关于阿里开发者招聘节 |这5道笔试真题 你会吗!???
查看>>
C#的异常处理机制
查看>>
写给MongoDB开发者的50条建议Tip13
查看>>