2
votes

This is driving me crazy.
I am under the impression that awakeFromNib Method is called only once(even when that view is visited again), correct me if i am wrong.

I have an app with 3 views. The last one being the subclass of a UIview where i draw using drawRect.

I had a working code with the method awakeFromNib in the last view, with the method being called only once how many ever times i visit the view.
Now i deploy the app to my device and update my Xcode to version 4.

When i run the code again and debug, the method awakeFromNib is called everytime the view is visited.
I dont think update would do such a crazy thing, but i am thoroughly confused.

Is there some kind of a memory leak or am i missing something?

Thank you

1

1 Answers

5
votes

I am under the impression that awakeFromNib Method is called only once(even when that view is visited again), correct me if i am wrong.

-awakeFromNib will be called on each instance of a class whenever an instance of that class is loaded from a nib file. You should be able to expect it to only be called once on a particular instance but should handle it being called many times on different instances of any given class.

UIViewControllers will unload their views when they receive a memory warning and their view is not visible. The view will be reloaded the next time the view controller's 'view' property is called. You should understand and support this behavior to minimize your app's memory use as it allows you to only keep the currently visible views in memory at any given time.

It sounds like you are not expecting that controller's view to be unloaded and reloaded from your nib.