How does loadNibNamed?

梦想的初衷 提交于 2020-01-02 04:51:10

问题


In most of the samples the return value from loadNibNamed value is not used, so I guess it's using the owner argument. But how does it work and make the connection to the owner object? What kind of requirements should my owner class meet in order to load a nib in such way?

The only requirements I can guess is that

  1. the owner class must have an outlet defined on or many of the objects in the nib file
  2. the nib file's owner SHOULD be set to the class where the nib is being loaded, then the owner param in loadNibNamed can be set to self
  3. the nib file should have all connections set to outlets defined in owner class

Am I right in my assumptions or is there anything else I have to consider while using loadNibNamed?


回答1:


You have a basic understanding of what is required, though you should also consider memory management (which is slightly different for iPhone versus Mac). To really understand what is going on with this method, you should read the Nib Files section of the Resources Programming Guide. It covers the actual methods used to make the connections (which can be important), and the retain counts that various objects will have when it is done. Again, these are all slightly different between Mac and iPhone. iPhone has generally improved the consistency of how nib objects are handled.

For good measure, I always recommend that people read Memory Management of Nib Objects from the Memory Management Programming Guide. It's critical reading whether you use the lower-level methods or not.



来源:https://stackoverflow.com/questions/3078013/how-does-loadnibnamed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!