Question

Sample: I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip

If viewDidLoad/viewInitWithNibName are called, a message box is displayed. The message box is not displayed, therefore, the methods are not being called.

Details: I have an application that is attempting to use a UITabBarController to switch between multiple views.

The views are linked up to the UITabBarController using interface builder (select the tab page, open Attributes (Option-1), and fill in the NIB Name field), and so are displayed "automatically" with no extra code-behind to make them appear.

Is it intended behaviour that views loaded like this do not have their viewDidLoad method executed? If not, how am I doing it wrong, and what do I need to change.

If it is intended behaviour, I can think of a few work-arounds, but any suggestions are appreciated:

  1. Scrap the UITabBarController and implement the view switching myself (using initWithNibName and add/insert/push/Subview).
  2. Call each of the children's viewDidLoad method manually in the UITabBarController's own viewDidLoad method.

Thank you in advance for any help you can offer.

Was it helpful?

Solution

OK, I've managed to solve this.

Linking the NIB to the TabBarController isn't enough - you also need to link the code beind file, it is not implicitly linked by the NIB even if you set the file owner correctly.

Open IB, and select the relevent page. Click in the middle to select the view controller. Enter the NIB name of the sub view, then go to the last page (option 4). In 'class identity', enter the name of the code-behind file for the sub-view NIB.

Everything will now work nicely.

I've uploaded a correct version of the sample code: http://uploads.omega.org.uk/Foo3-Correct.zip

OTHER TIPS

You're not instantiating ImportedView anywhere in your project, so it's not calling either initXXX or viewDidAnything. If you put your alert code in -[FirstViewController viewDidLoad], it'll fire as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top