请参阅此代码,它提供了2个带导航的tabbar。 在AppDelegate.h
请声明
UINavigationController *nav1;
UINavigationController *nav2;
UITabBarController *tab;
而在Appdelegate.m
,在didFinishLaunchingWithOptions
请加: -
tab = [[UITabBarController alloc]init];
ViewController *view1 = [[ViewController alloc]init];
nav1= [[UINavigationController alloc]initWithRootViewController:view1];
UITabBarItem *tab1 = [[UITabBarItem alloc]initWithTitle:@"Add" image:[UIImage imageNamed:@"Plus.png"] tag:1];
view1.title = @"Add";
[view1 setTabBarItem:tab1];
SettingsViewController *view2 = [[SettingsViewController alloc]init];
nav2= [[UINavigationController alloc]initWithRootViewController:view2];
UITabBarItem *tab2 = [[UITabBarItem alloc]initWithTitle:@"Setting" image:[UIImage imageNamed:@"settings.png"] tag:2];
view2.title = @"Setting";
[view2 setTabBarItem:tab2];
tab.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nil];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = tab;
还要检查这个环节进一步落实......希望这有助于:)
UItabBar changing View Controllers
谢谢!但我可以做到没有导航控制器? – user1559227