From what I have read on the internet, nibs and storyboards are comparable with each other in the same project. Now I am creating a tabbed application and would like to do the following:
Tab 1: constructed with nibs,
Tab 2: constructed with storyboards,
Tab 3: constructed with nibs
Initially I created everything with nibs so in my delegate I was passing from one tab to the next with this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil] autorelease];
viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPhone" bundle:nil] autorelease];
} else {
viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController_iPad" bundle:nil] autorelease];
viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController_iPad" bundle:nil] autorelease];
viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController_iPad" bundle:nil] autorelease];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Instead of having the SecondViewController_.xib I need to have the SecondViewController_.storyboard. How do I do this? Can I just change the name "SecondViewController_.nib" to "SecondViewController_.storyboard"? I don't think this would work..
Any help would be very appreciated!!
EDIT: the code i was using :
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Events", @"Events");
self.tabBarItem.image = [UIImage imageNamed:@"second"];
}
return self; }
You could do what you're suggesting by creating a storyboard and then creating a
SecondViewController
scene inside it. In code, you would then replaceinitWithNibName:
with calls tostoryboardWithName:
andinstantiateViewControllerWithIdentifier:
.However, since a major feature in storyboards is the ability to tie multiple controllers together and define relationships between them, it's hard to imagine why doing it for one controller would be a good idea.