内存初始化和viewdidload以及事件执行顺序
我正在尝试使用 ALAssetsLibrary 和 enumerateGroupsWithTypes 加载资产列表。我用加载的资源填充 NSMutableArrary ,以便稍后使用它,例如随机更改视图的背景。
我尝试使用 ViewDidLoad 方法中的资源预加载此数组,结果发现它在加载视图后得到处理。如果我在调用 load 方法之后放置 NSLog 语句,则会打印日志,但在视图完全加载之前不会初始化数组。
问题是我什么时候应该初始化我的数组?
谢谢!
I am trying to load a list of assets using the ALAssetsLibrary and enumerateGroupsWithTypes. I populate an NSMutableArrary with the assets loaded so i get to use it later, for instance change a view's background randomly.
I tried to preload this array with the assets in the ViewDidLoad method and only to find out that it gets handled AFTER the view is loaded. if I put a NSLog statement after the load method is called, the log will be printed, but no array initialized until the view is completely loaded.
Question is when should I initialize my array then?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
viewDidLoad
方法完全按照它的建议执行 - 一旦视图加载,它就会被调用。那里没有什么惊喜。您可以考虑加载initWithFrame:
和/或initWithCoder:
方法,具体取决于与您相关的方法。您的问题并没有说明为什么要在此方法中加载某些内容。将其加载到 viewDidLoad 方法并在视图出现之前使用数组配置视图有什么问题吗?我不知道你的负载有多重。但你猜怎么着 - 甚至还有一个方便的
viewWillAppear:
方法...!The
viewDidLoad
method does exactly as it suggests - its called once the view is loaded. No surprises there. You could consider loading in theinitWithFrame:
and/orinitWithCoder:
methods, depending on which is relevant to you.Your question doesn't say much about why you want to load something in this method. What's wrong with loading it in, say, the
viewDidLoad
method and using the array to configure the view before the view will appear? I have no idea how heavy your loading is. But guess what - there's even a handyviewWillAppear:
method...!