memory initialization and viewdidload and order of event execution
I am trying to load a 开发者_如何学Clist 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!
The viewDidLoad
method does exactly as it suggests - its called once the view is loaded. No surprises there. You could consider loading in the initWithFrame:
and/or initWithCoder:
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 handy viewWillAppear:
method...!
精彩评论