您好我有一些代碼我更新的iOS 7,所以我有一個在這裏列出的問題:iOS 7 Status Bar Collides With NavigationBar如何導航控制器添加到程序標籤欄
所以我試圖修復它。在我的RestaurantSearch視圖上,我添加了一個導航控制器。問題是現在我的代碼與此錯誤崩潰:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "RestaurantSearch" nib but the view outlet was not set.'
我不知道該怎麼設置插座。之前它只是一個視圖,它被設置爲文件的所有者。這不再是一種選擇。
這裏是我在這一行[selfView.navigationController pushViewController:tab animated:YES];
這裏的標籤欄
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;
}
發生崩潰的代碼是我的導航視圖設置的屏幕截圖。
我想這可能是這個問題的一個可能重複Loaded nib but the view outlet was not set - new to InterfaceBuilder
然而,當我按照指示,我收到一個新的錯誤:
'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>.'
我的猜測是,我掛鉤的東西了不正確,但我不確定是什麼。我ctr +從導航控制器拖到我上面的圖像中的視圖。這可能與它有關嗎?
你可能想看看http://stackoverflow.com/questions/13835724/programming-tabbarcontroller-with-navigation-in -appdelegate/13839852#13839852 –
我不使用StoryBoard,是否可以在不使用StoryBoard的情況下使用導航控制器? – tomjung
該鏈接的解決方案不使用storyboard,它解釋瞭如何以編程方式將一個導航控制器添加到tabview控制器(我隱約記得相反不可能?) 但是,解決方案「[self.window setRootViewController:tab]; 「可能是你所需要的,因爲你的錯誤是非常具有描述性的,並且確切地說出了什麼錯誤:你有兩個視圖控制器被這個視圖使用! –