I've worked in iOS completely programmatically and I've worked completely with IB, but I'm trying to mix the two for the first time and I'm getting confused. I'm writing a tabbed application. In my app delegate, I used to have the following code:
//...Code setting view controllers for various tab items and then this...
GHSettingsViewController *svc = [[GHSettingsViewController alloc] init];
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];
And that was fine.
Then I created a view controller via storyboard in IB and added a bunch of UI elements to it, giving it the following settings:
Now my code reads:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
GHSettingsViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"settings"];
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];
The application launches fine, but when I press the tab to go to the settings screen, I get the following message:
What does this mean and how can I fix it?
EDIT: Here's a fuller version of the code from the app delegate in didFinishLaunching
:
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:5];
GHHaikuViewController *hvc = [[GHHaikuViewController alloc] init];
hvc.tabBarItem.title = @"Home";
hvc.tabBarItem.image = [UIImage imageNamed:@"53-house.png"];
[tabItems addObject:hvc];
GHComposeViewController *cvc = [[GHComposeViewController alloc] init];
cvc.tabBarItem.title = @"Compose";
cvc.tabBarItem.image = [UIImage imageNamed:@"216-compose.png"];
[tabItems addObject:cvc];
GHWebViewController *wvc = [[GHWebViewController alloc] init];
wvc.tabBarItem.title = @"Buy";
wvc.tabBarItem.image = [UIImage imageNamed:@"80-shopping-cart.png"];
[tabItems addObject:wvc];
GHFeedback *fvc = [[GHFeedback alloc] init];
fvc.tabBarItem.title = @"Feedback";
fvc.tabBarItem.image = [UIImage imageNamed:@"18-envelope.png"];
[tabItems addObject:fvc];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
//UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard.storyboard" bundle:nil]; //Using this instead causes the application to crash on launching.
GHSettingsViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"settings"];
//GHSettingsViewController *svc = [storyboard instantiateInitialViewController]; //Using this instead of the line above causes the same error.
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];
GHTabBarController *tbc = [[GHTabBarController alloc] init];
tbc.viewControllers = tabItems;
self.window.rootViewController = tbc;
return YES;
}
prepareForSegue
method. You can refer to it withGHSettingsViewController *svc = (GHSettingsViewController*)[segue destinationViewController]
; – Aaron Brager