ViewController学习笔记

本文深入探讨了iOS应用中视图控制器在加载与卸载周期中的关键步骤,包括如何创建视图、处理内存警告及释放资源,提供了一套全面的视图管理策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The steps that occur during the load cycle are as follows:

  1. Some part of your application asks for the view in the view controller’s view property.

  2. If the view is not currently in memory, the view controller calls its loadView method.

  3. The loadView method does one of the following:

    ● If you override this method, your implementation is responsible for creating all necessary views and assigning a non-nil value to the view property.

    ● If you do not override this method, the default implementation uses the nibName and nibBundle properties of the view controller to try to load the view from the specified nib file. If the specified nib file is not found, it looks for a nib file whose name matches the name of the view controller class and loads that file.

    ● If no nib file is available, the method creates an empty UIView object and assigns it to the view property.

  4. The view controller calls its viewDidLoad method to perform any additional load-time tasks. 

 

The steps that occur during the unload cycle are as follows:

  1. The application receives a low-memory warning from the system.

  2. Each view controller calls its didReceiveMemoryWarning method:

    • ●  If you override this method, you should use it to release any custom data that your view controller object no longer needs. You should not use it to release your view controller’s view. You must call super at some point in your implementation to perform the default behavior.

    • ●  The default implementation releases the view only if it determines that it is safe to do so.

  3. If the view controller releases its view, it calls its viewDidUnload method. You can override this method

    to perform any additional cleanup required for your views and view hierarchy.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值