gpt4 book ai didi

objective-c - nib 中顶级对象的加载顺序

转载 作者:行者123 更新时间:2023-12-03 17:30:22 25 4
gpt4 key购买 nike

nib 文件中顶级对象的加载顺序是随机的还是可以确定的?我认为它会按照我在 Interface Builder 中放入对象的顺序加载对象。但情况似乎并非总是如此。

我想创建一个类似于 Interface Builder 的检查器 View ,其中不同的部分具有交替的背景颜色。我计划通过将这些部分排序为我的 Nib 中的顶级 View ,然后根据加载顺序为它们着色来实现此目的。

最佳答案

根据文档,加载顺序未定义:

The order in which the nib-loading code calls the awakeFromNib methods of objects is not guaranteed. In OS X, Cocoa tries to call the awakeFromNib method of File’s Owner last but does not guarantee that behavior. If you need to configure the objects in your nib file further at load time, the most appropriate time to do so is after your nib-loading call returns. At that point, all of the objects are created, initialized, and ready for use.

参见https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html

无论如何,依靠加载顺序之类的东西来确定视觉布局似乎是一个非常不可靠的想法。我会使用 NSTableView/UITableView,它将为您完成布局、交替行颜色等。 (在 Mac 上,您可能需要基于 View 的表格 View )。如果您出于某种原因需要自定义解决方案,请在代码中动态加载和添加 View ,您可以完全控制它们在父级中的顺序和位置。

关于objective-c - nib 中顶级对象的加载顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10873761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com