Hi I have some code I'm updating for iOS 7, so I have the problem that is outlined here:iOS 7 Status Bar Collides With NavigationBar
So I'm trying to fix it. On my RestaurantSearch View I have added a Navigation Controller. Problem is now my code crashes with this error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "RestaurantSearch" nib but the view outlet was not set.'
I'm not sure what to set the outlet too. Before when it was just a view it was set to the File's Owner. That's not an option anymore.
Here is my code for the tab bar
void SetTabbar(UIViewController *selfView)
{
UITabBarController *tab = [[[UITabBarController alloc] init] autorelease];
nibName = NIB_NAME(@"RestaurantSearch");
RestaurantSearch *vc1 = [[RestaurantSearch alloc] initWithNibName:nibName bundle:nil];
UINavigationController *nav1 = [[[UINavigationController alloc] initWithRootViewController:vc1] autorelease];
nav1.tabBarItem.title = @"Search";
nav1.tabBarItem.image = [UIImage imageNamed:@"search_on.png"];
[nav1.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"green_search_on.png"] withFinishedUnselectedImage:nil];
nav1.navigationBarHidden = YES;
nibName = NIB_NAME(@"Friends");
Friends *vc2 = [[Friends alloc] initWithNibName:nibName bundle:nil];
UINavigationController *nav2 = [[[UINavigationController alloc] initWithRootViewController:vc2] autorelease];
nav2.tabBarItem.title = @"Friends";
nav2.tabBarItem.image = [UIImage imageNamed:@"contact_on.png"];
[nav2.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"green_contact_on.png"] withFinishedUnselectedImage:nil];
nav2.navigationBarHidden = YES;
nibName = NIB_NAME(@"RewardList");
RewardList *vc3 = [[RewardList alloc] initWithNibName:nibName bundle:nil];
UINavigationController *nav3 = [[[UINavigationController alloc] initWithRootViewController:vc3] autorelease];
nav3.tabBarItem.title = @"Reward";
nav3.tabBarItem.image = [UIImage imageNamed:@"reward_on.png"];
[nav3.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"green_reward_on.png"] withFinishedUnselectedImage:nil];
nav3.navigationBarHidden = YES;
nibName = NIB_NAME(@"MoreViewController");
MoreViewController *vc4 = [[MoreViewController alloc] initWithNibName:nibName bundle:nil];
UINavigationController *nav4 = [[[UINavigationController alloc] initWithRootViewController:vc4] autorelease];
nav4.tabBarItem.title = @"More";
nav4.tabBarItem.image = [UIImage imageNamed:@"more_on.png"];
[nav4.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"green_more_on.png"] withFinishedUnselectedImage:nil];
nav4.navigationBarHidden = YES;
// Change the tabbar's background and selection image through the appearance proxy
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar_bg_flat.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selection_flat.png"]];
NSArray *array = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
[tab setViewControllers:array];
// Text appearance values for the tab in normal state
NSDictionary *normalState = @{
UITextAttributeTextColor : [UIColor colorWithWhite:0.213 alpha:1.000],
UITextAttributeTextShadowColor: [UIColor whiteColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0, 1.0)]
};
// Text appearance values for the tab in highlighted state
NSDictionary *selectedState = @{
UITextAttributeTextColor : [UIColor blackColor],
UITextAttributeTextShadowColor: [UIColor whiteColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0, 1.0)]
};
[[UITabBarItem appearance] setTitleTextAttributes:normalState forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:selectedState forState:UIControlStateHighlighted];
[selfView.navigationController pushViewController:tab animated:YES];
g_tabbar = tab;
}
The crash occurs on this line [selfView.navigationController pushViewController:tab animated:YES];
Here is a screen shot of my Navigation View setup.
I thought this might be a possible duplicate of this question Loaded nib but the view outlet was not set - new to InterfaceBuilder
However when I follow instructions, I receive a new error:
'A view can only be associated with at most one view controller at a time! View <UIView: 0x1dd45ae0; frame = (0 0; 320 460); autoresize = W+H; autoresizesSubviews = NO; layer = <CALayer: 0x1dd45b40>> is associated with <RestaurantSearch: 0x1dd28e20>. Clear this association before associating this view with <RestaurantSearch: 0x1f03df70>.'
My guess is I'm hooking something up incorrectly, but I'm not sure what. I ctr+dragged from Navigation Controller to my View in the image above. Could this have something to do with it?