博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
awakeFromNib and applicationDidFinishLaunching
阅读量:6517 次
发布时间:2019-06-24

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

awakeFromNib is called on every object that is initialized or referenced from within a nib file.

In this nib file, I have references to two pieces of custom code: The Window Controller and the Window itself. So which of these two gets the awakeFromNib call? Both do.

Specifically, when a nib file has completed initializing all of the objects, it then loops back through every object referenced in the nib and if the object responds to awakeFromNib, it calls awakeFromNib on the object. Therefore, you can have logic in any or all of your objects in the awakeFromNib call.

Call order

In the second example above, it is possible to have an awakeFromNib method and an applicationDidFinishLaunching: method in the AppDelegate. Which would be called first and why?

The answer is that the awakeFromNib will be called first. When the nib file has been initialized, each object referenced in the nib will be looped through and they will all receive an awakeFromNib call if they respond to the message. After all of that is done then the Application’s delegate will receive the applicationDidFinishLaunching: call. This is the notice that everything is loaded and that the application is ready to start receiving user input.

Conclusion

If your code is localized to only the object you are working with then putting the code in the awakeFromNib is the perfect place for it. However, if your code is going to be manipulating more than one object in the nib then it is probably safer to put it in the applicationDidFinishLaunching: instead. This will insure that everything is loaded, referenced and ready to go.

 
 

 

转载于:https://www.cnblogs.com/grep/archive/2012/07/08/2581799.html

你可能感兴趣的文章
五花八门的计算机语言
查看>>
基于Yum安装zabbix3.0
查看>>
MySQL查询按照指定规则排序
查看>>
Lua一系列很好的技术分享文章链接: 快速掌握 Lua 5.3
查看>>
MVC有点和不足
查看>>
PHP class
查看>>
Action 分发机制实现原理
查看>>
kvm虚拟化
查看>>
protobuf使用之proto文件编写规则
查看>>
Play Mongo 模块简介
查看>>
WinScp使用时小功能
查看>>
python视频教程包含全部代码实例,,需要的单播给我.
查看>>
Nginx HTTP返回状态码修改
查看>>
网站自动点击,支持代理更换
查看>>
第二讲:tapestry增删改查---添加数据
查看>>
动态加载JS,CSS文件
查看>>
Java NIO系列教程
查看>>
Android移动端音视频的快速开发教程(九)
查看>>
基本知识
查看>>
二:JVM学习-垃圾收集算法以及常用的垃圾收集器
查看>>