首先明确Tab bar 的优先级别最高,思路:先将ViewController放入UINavigationController ,再将多个UINavigation放入Tab bar
例子:首先建了一个Tab bar.xibwen文件
随后在AppDelegate.m文件
假设已经建了三个ViewController文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.mArray = [NSMutableArray array];
YcwFirstViewController *firstViewController = [[YcwFirstViewController alloc]initWithNibName:@"YcwFirstViewController" bundle:nil];
UINavigationController *firstNavigation = [[UINavigationController alloc]initWithRootViewController:firstViewController];
YcwSecondViewController *secondViewController =[[YcwSecondViewController alloc]initWithNibName:@"YcwSecondViewController" bundle:nil];
UINavigationController *secondNavigation = [[UINavigationController alloc]initWithRootViewController:secondViewController];
YcwThirdViewController *thirdViewController = [[YcwThirdViewController alloc]initWithNibName:@"YcwThirdViewController" bundle:nil];
UINavigationController *thirdNavigation = [[UINavigationController alloc]initWithRootViewController:thirdViewController];
NSArray *array_controlller = [NSArray arrayWithObjects:firstNavigation,secondNavigation,thirdNavigation, nil];
UITabBarController *myTabBarController = [[UITabBarController alloc]init];
myTabBarController.viewControllers = array_controlller;
self.window.rootViewController = myTabBarController;
[self.window makeKeyAndVisible];
return YES;
}
随后在每个视图的 (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
内设置tabBarItem.title
和tabBarItem.image属性即可显示小图标和title
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem.title = @"third";
self.tabBarItem.image = [UIImage imageNamed:@"333.png"];
}
return self;
}