ios uiview 子视图加载事件
有没有一种简单的方法可以知道所有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从 viewController 调用此函数,只需使用
在加载视图及其所有子视图后调用 Which 即可。如果您从笔尖内的视图之一执行此操作,请使用:
在加载视图的子视图后调用它。
If you're calling this from a viewController, just use
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:
Which is called after the view's subviews have been loaded.
如果您以编程方式添加子视图(例如
[myView addSubview:anotherView]
),那么当然没有办法知道;如果您这样编写,程序可以随时添加更多子视图。如果您从笔尖加载视图,您可能正在寻找
awakeFromNib
方法。来自NSObject UIKit Additions Reference< /em>: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: