ios uiview 子视图加载事件

发布于 2025-01-01 22:04:26 字数 381 浏览 0 评论 0原文

有没有一种简单的方法可以知道所有 subivews 何时加载?

现在我正在做:

if([[self subviews] count] == 10) {
    //do stuff
}

如果没有为此的事件/方法,是否至少有一种方法可以动态地知道子计数将会是多少?

编辑

我刚刚重新阅读了这篇文章,并意识到这有点愚蠢。让我澄清一下:

我正在从 XIB 文件加载此 UIView,我想知道 NIB 何时正式加载(包含所有这是孩子们)。所以我敢说正确的答案是awakeFromNib

Is there an easy way to know when all the subivews have loaded?

Right now I'm doing:

if([[self subviews] count] == 10) {
    //do stuff
}

If there isn't an event/method for this, is there at least a way to dynamically know what the child count is GOING to be?

edit

I re-read this just now and realize it's a bit asinine. Let me clarify:

I'm loading this UIView from a XIB file and I wanted to know when the NIB has officially loaded (with all of it's children). So I dare say the correct answer would be awakeFromNib

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

洛阳烟雨空心柳 2025-01-08 22:04:26

如果您从 viewController 调用此函数,只需使用

-(void)viewDidLoad;

在加载视图及其所有子视图后调用 Which 即可。如果您从笔尖内的视图之一执行此操作,请使用:

-(void)awakeFromNib;

在加载视图的子视图后调用它。

If you're calling this from a viewController, just use

-(void)viewDidLoad;

Which is called after the view and all its subviews are loaded. If you're doing it from one of the views inside the nib, use:

-(void)awakeFromNib;

Which is called after the view's subviews have been loaded.

§对你不离不弃 2025-01-08 22:04:26

如果您以编程方式添加子视图(例如[myView addSubview:anotherView]),那么当然没有办法知道;如果您这样编写,程序可以随时添加更多子视图。

如果您从笔尖加载视图,您可能正在寻找 awakeFromNib 方法。来自NSObject UIKit Additions Reference< /em>

nib 加载基础结构会向从 nib 存档重新创建的每个对象发送一条 awakeFromNib 消息,但前提是存档中的所有对象均已加载并初始化。当对象收到 awakeFromNib 消息时,保证已建立其所有出口和操作连接。

If you are adding subviews programmatically (e.g. [myView addSubview:anotherView]), then of course there is no way to know; the program could add more subviews at any time, if you write it that way.

If you are loading the view from a nib, you are probably looking for the awakeFromNib method. From the NSObject UIKit Additions Reference:

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文