views:

30

answers:

1

I am attempting to create a basic tab-bar application using interface builder. I create a new project in Xcode selecting tab bar application.

My question is how can I access the code that instantiates and pushes each of the views when the tab bar buttons are pressed? I would imagine that would be done by the tab bar controller, however when I write the class file from interface builder (file>write class files), it just creates a blank generic TabBarController.h/TabBarController.m without the methods for pushing each of the views associated with the tab bar elements.

I ask this because I would like to pass each view controller a reference to the data model when they are instantiated. Any help would be greatly appreciated, thanks.

A: 

You're not missing any hidden code because there simply isn't any. Interface Builder is not a code generator. When you put objects into a NIB file in IB, IB archives them and your app unarchives them when it loads the NIB.

So assuming you have created the tab bar controller with all its subcontrollers in MainWindow.xib, all these objects will have been instantiated when your code reaches application:didFinishLaunchingWithOptions:.

Ole Begemann
If I wanted to add a few lines of code that execute when a tab bar item is pressed, where would I add those?
That's a different question because the instantiation of the tab bar controller's subcontrollers happens when you create the tabs, not when the user selects one. Set yourself as the tab bar controller's delegate and implement `tabBarController:didSelectViewController:`.
Ole Begemann