我使用2 TabBarController
创建基本ViewControllers
。
它有效,但它有bug,我想要它的一些东西。
的问题1。 的
当我运行时(默认ViewController is FirstViewController
)SecondViewController
中的TabBar
名称未显示。
我想要关注这张照片。
的 Problem2。 的
在我的代码中,默认视图为FirstViewController
。
如果我想设置默认视图是SecondViewController
通过相同标签栏(FirstView
标签:左侧和SecondView
标签:右侧)
跟着这张照片。如何解决它。
这是我的示例代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FirstViewController *firstVC = [[FirstViewController alloc] init];
UINavigationController *firstNVC = [[UINavigationController alloc] initWithRootViewController:firstVC];
firstNVC.navigationBar.barStyle = UIBarStyleBlack;
SecondViewController *secondVC = [[SecondViewController alloc] init];
UINavigationController *secondNVC = [[UINavigationController alloc] initWithRootViewController:secondVC];
secondNVC.navigationBar.barStyle = UIBarStyleBlack;
UITabBarController *tabController = [[UITabBarController alloc]init];
tabController.navigationItem.hidesBackButton = NO;
tabController.viewControllers = [NSArray arrayWithObjects:firstNVC, secondNVC, nil];
tabController.navigationController.navigationBarHidden = NO;
self.window.rootViewController = tabController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
谢谢。 ^^
答案 0 :(得分:0)
问题2. 如果我愿意的话 设置默认视图是Same Tab Bar的SecondViewController(FirstView Tab :左,和SecondView选项卡:右)。如何 解决它。
<强>解决方案:强>
[self.tabBarController setSelectedIndex:1];
答案 1 :(得分:0)
问题1:
尝试为视图控制器设置标题。
问题2:
您只需将tabBarController的选定索引设置为1即可。
答案 2 :(得分:0)
<强>问题1 强>
您尚未为每个导航控制器设置tabbarItem
,我认为您应首先设置带有标题的UITabBarItem
,然后将其分配给导航控制器tabbarItem
属性。
<强> Problem2 强>
正如@Kumar所说。
答案 3 :(得分:0)
UIViewController *viewController1 = [[[viewController1 alloc] initWithNibName:@"viewController1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[viewController2 alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
UIViewController *viewController3 = [[[viewController3 alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
navControl1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navControl2=[[UINavigationController alloc]initWithRootViewController:viewController2];
navControl3=[[UINavigationController alloc]initWithRootViewController:viewController3];
navControl1.navigationBar.tintColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
navControl2.navigationBar.tintColor=[UIColor blackColor];
navControl3.navigationBar.tintColor=[UIColor blackColor];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.delegate=self;
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navControl2,navControl1,navControl3, nil ];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@""] withFinishedUnselectedImage:[UIImage imageNamed:@""]];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setTitle:@"1"];
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setImage:[UIImage imageNamed:@"tab2.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setTitle:@"2"];
[[[[self.tabBarController tabBar] items] objectAtIndex:1] setImage:[UIImage imageNamed:@"tab11.png"]];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setTitle:@"3"];
[[[[self.tabBarController tabBar] items] objectAtIndex:2] setImage:[UIImage imageNamed:@"tab5.png"]];
[self.tabBarController.tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"trans.png"]];
UIImage* tabBarBackground = [UIImage imageNamed:@""];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"trans.png"]];