简体   繁体   中英

Init NSObjects from MainMenu.xib

In MainMenu.xib I can drop NSObjects to create class instances. Is the vertical order in which these objects are dropped is the order in which they will be allocated? Can I rely on that?

No, you can't rely on the order in which objects are listed to be the order in which they are instantiated. You can rely on the fact that once awakeFromNib is called on objects in your nib, all objects have been instantiated and all connections between objects have been created.

What are you trying to do?

If you are talking about using the GUI to drag into the .h files to create properties and methods. Then it doesn't matter what order they are in.

If the elements are related and need to be allocated in a certain order. Then you can go into the .m files and changed the order manually of when then they are allocated or hide certain elements until they are needed.

You can test this, and rely on, for a while. Nib editor (Xcode) saves object descriptions to nib file in undescribed manner. Nib unarchiving (init...) order is not well-defined, too. AwakeFromNib order is not guaranteed explicitly (this one is stated in manual). Everything may change with next Xcode or cocoa version.

Verdict: no.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM