4
votes

I am working on an Iphone application. I am using a StoryBoard.

I have a Tab View with 3 tabs. "Home", "Users" and "Settings".

I create the "Home" and "Users" view on the story board, but The settings view is a XIB file (SettingsView.xib)

How can I make the third tab ("Settings") open the SettingsView.xib? Can I use both the story board and xib files?

I tried to initialize a UINavigationController in the startApp method in the AppDelegate but I can't find out how to add it to the story board.

Thanks for any help

2
This is two questions, and almost certainly a duplicate; hope my answer works for you.Gordon Dove

2 Answers

3
votes

TabViewControllers usually have one navigation controller for each tab. Create the navigation controllers in storyboard and connect them to the navigationcontrollers relation of the tab view controller.

The initial view of the navigation controller connects to the rootViewController relationship of the navigation controller.

As to your second question, I'm not certain, but I think the following will work:-

Create a UIViewController in storyboard and change it's class to your class that you're loading from an XIB. When the storyboard instantiates the class, it will use the XIB provided the class name of the class exactly matches the name of the XIB. I don't think you can do any iPad/iPod checking here though.

0
votes

You can add a xib-based view to your storyboard-based tab bar controller as follows. I am assuming the following:

  • The tab bar controller is the initial view controller of your storyboard.
  • Your settings controller is a class called SettingsController
  • You have a tab bar image in your bundle called SettingsTabImage

Define the tab bar controller in the storyboard with just your storyboard-based tab bar items in it - Home and Users in your case

In your application delegate, use the following code in application:didFinishLaunchingWithOptions::

// Create your settings view controller
SettingsController *settingsVC = [[SettingsController alloc] initWithNibName:nil bundle:nil];

// Create a tab bar item
UITabBarItem *settingsItem = [[UITabBarItem alloc] initWithTitle:@"Settings" image:[UIImage imageNamed:@"SettingsTabImage" tag:0];
settingsVC.tabBarItem = settingsItem;

// Get a reference to the tab bar controller
UITabBarController *tbC = (UITabBarController*)self.window.rootViewController;

// Get the current view controllers in your tab bar
NSMutableArray *currentItems = [NSMutableArray arrayWithArray:tbC.viewControllers];

// Add your settings controller
[currentItems addObject:settingsVC];
tbC.viewControllers = [NSArray arrayWithArray:currentItems];