Tab bar和UINavigationController同时使用

首先明确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;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值