請參閱此代碼,它提供了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