Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a Navigation Controller to a programmed tab bar
    primarykey
    data
    text
    <p>Hi I have some code I'm updating for iOS 7, so I have the problem that is outlined here:<a href="https://stackoverflow.com/questions/19105766/ios-7-status-bar-collides-with-navigationbar">iOS 7 Status Bar Collides With NavigationBar</a></p> <p>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:</p> <pre><code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "RestaurantSearch" nib but the view outlet was not set.' </code></pre> <p>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. </p> <p>Here is my code for the tab bar</p> <pre><code>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; } </code></pre> <p>The crash occurs on this line <code>[selfView.navigationController pushViewController:tab animated:YES];</code></p> <p>Here is a screen shot of my Navigation View setup. <img src="https://i.stack.imgur.com/VXDaX.png" alt="Screen Shot"></p> <p>I thought this might be a possible duplicate of this question <a href="https://stackoverflow.com/questions/4763519/loaded-nib-but-the-view-outlet-was-not-set-new-to-interfacebuilder">Loaded nib but the view outlet was not set - new to InterfaceBuilder</a></p> <p>However when I follow instructions, I receive a new error:</p> <pre><code>'A view can only be associated with at most one view controller at a time! View &lt;UIView: 0x1dd45ae0; frame = (0 0; 320 460); autoresize = W+H; autoresizesSubviews = NO; layer = &lt;CALayer: 0x1dd45b40&gt;&gt; is associated with &lt;RestaurantSearch: 0x1dd28e20&gt;. Clear this association before associating this view with &lt;RestaurantSearch: 0x1f03df70&gt;.' </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload