Strange Behaviour of tabbarcontroller

204 views Asked by At

I have a tab bar application and i am encountering a strange behaviour....when i toggle the tab bar and reaches into new view controllers sometimes the viewDidLoad of these view controllers are getting called...though viewDidLoad should get called only first time... can anyone tell...any suggestion??

3

There are 3 answers

0
deanWombourne On BEST ANSWER

If there's a low memory warning then a tab bar controller will release all views that are not visible. This means that you can get viewDidLoad called more than once because the view has been unloaded.

0
Enrico Susatyo On

Are you sure it's viewDidLoad, not viewWillAppear?

viewDidLoad will only be called once in each UIViewController subclass, so if your layout is like this:

-UITabBarController:
    - HappyUIViewController
    - SadUIViewController
    - ThirdUIViewController

Then viewDidLoad will be called three times. Once for HappyUIViewController, once for SadUiViewController, and so on.

4
Matthew Frederick On

Is your app memory-intensive, perhaps to the point that you're receiving memory warning? Though I have not experienced the behavior you're describing, it's possible that due to heavy memory use your unseen views are being released due to a lack of memory. When they're next called into view they would need to be reinitialized, calling viewDidLoad.