- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我有一些代码正在为 iOS 7 更新,所以我遇到了此处概述的问题:iOS 7 Status Bar Collides With NavigationBar
所以我正在尝试修复它。在我的 RestaurantSearch View 中,我添加了一个导航 Controller 。现在的问题是我的代码因这个错误而崩溃:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "RestaurantSearch" nib but the view outlet was not set.'
我也不确定要设置什么 socket 。在它只是一个 View 之前,它被设置为文件的所有者。这不再是一种选择。
这是我的标签栏代码
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;
}
崩溃发生在这一行 [selfView.navigationController pushViewController:tab animated:YES];
这是我的导航 View 设置的屏幕截图。
我认为这可能是这个问题的重复 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>.'
我的猜测是我连接不正确,但我不确定是什么。在上图中,我从 Navigation Controller 按 ctr+拖动到我的 View 。这可能与它有关吗?
最佳答案
您应该将标签栏添加到您的应用程序的根导航 Controller 中。标签栏需要是 Root View Controller 。您不能将其推送到 View Controller subview 。您需要将其添加到 applicationDidFinishLaunching: 方法中的窗口,例如:
[self.window setRootViewController:tab];
关于ios - 如何将导航 Controller 添加到已编程的选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20477148/
我是一名优秀的程序员,十分优秀!