RootTabBarController.m 4.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
//  RootTabBarController.m
//  redstar
//
//  Created by admin on 15/11/3.
//  Copyright © 2015年 ZWF. All rights reserved.
//

#import "RootTabBarController.h"

#import "HomeViewController.h"
#import "AnnounceViewController.h"
#import "ChartViewController.h"
#import "MineViewController.h"

16 17 18
#import <AFNetworking.h>
#import "CommonFunc.h"

19 20 21 22 23 24 25 26
@interface RootTabBarController ()
@end

@implementation RootTabBarController

- (void)viewDidLoad
{
    [self setupTabbar];
27
        
admin's avatar
admin committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    self.delegate = self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.parentViewController.tabBarController.tabBar.hidden = YES;

}

- (void)viewDidDisappear:(BOOL)animated
{
    self.parentViewController.tabBarController.tabBar.hidden = YES;

43 44
}

45

46 47 48 49 50
//
- (void)setupTabbar
{
    // 跳转到tabbarController
    
admin's avatar
admin committed
51 52 53 54
    HomeViewController *home = (HomeViewController *)[self setUpOneChildViewController:[[HomeViewController alloc] init] title:@"首页" imageName:@"home_unchecked" selImageName:@"home_checked"];
    UINavigationController *homeNav = [[UINavigationController alloc] initWithRootViewController:home];
    [homeNav.navigationBar setBarTintColor:kNavigationBarColor];
    [homeNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
55 56
    
    
admin's avatar
admin committed
57
    AnnounceViewController *announce = (AnnounceViewController *)[self setUpOneChildViewController:[[AnnounceViewController alloc] init] title:@"功能" imageName:@"function_uncheck" selImageName:@"function_check"];
admin's avatar
admin committed
58 59 60 61
    // 添加nav
    UINavigationController *announceNav = [[UINavigationController alloc] initWithRootViewController:announce];
    [announceNav.navigationBar setBarTintColor:kNavigationBarColor];
    [announceNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
62
    
admin's avatar
admin committed
63 64 65 66
    ChartViewController *chart = (ChartViewController *)[self setUpOneChildViewController:[[ChartViewController alloc] init] title:@"报表查询" imageName:@"report_unchecked" selImageName:@"report_checked"];
    UINavigationController *chartNav = [[UINavigationController alloc] initWithRootViewController:chart];
    [chartNav.navigationBar setBarTintColor:kNavigationBarColor];
    [chartNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
67
    
admin's avatar
admin committed
68 69 70 71
    MineViewController *mine = (MineViewController *)[self setUpOneChildViewController:[[MineViewController alloc] init] title:@"我的" imageName:@"aboutme_unchecked" selImageName:@"aboutme_checke"];
    UINavigationController *mineNav = [[UINavigationController alloc] initWithRootViewController:mine];
    [mineNav.navigationBar setBarTintColor:kNavigationBarColor];
    [mineNav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
72 73 74 75
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       kNavigationBarColor, NSForegroundColorAttributeName,
                                                       nil] forState:UIControlStateSelected];
admin's avatar
admin committed
76 77

    self.viewControllers = @[homeNav, announceNav, chartNav, mineNav];
78 79 80 81 82
}



// 添加一个控制器的属性
admin's avatar
admin committed
83
- (UIViewController *)setUpOneChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName selImageName:(NSString *)selImageName
84 85 86 87 88 89 90 91
{
    // 添加TabBar按钮的图片文字
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    UIImage *selImage = [UIImage imageNamed:selImageName];
    selImage = [selImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selImage;
    
admin's avatar
admin committed
92 93 94
    return vc;
    
    
95 96
}

admin's avatar
admin committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#pragma mark - UITabBarController Delegate
//
//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
//    NSLog(@"shouldSelectViewController  %@", tabBarController.selectedViewController);
//    if (viewController.tabBarItem.tag == 30001) {
//        [((UINavigationController *)tabBarController.selectedViewController) pushViewController:viewController animated:YES];
//        return NO;
//    }
//    return YES;
//}

//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
//{
//    if ([viewController isKindOfClass:[MineViewController class]]) {
//        MineViewController *mine = [[MineViewController alloc] init];
//        mine.tabBarItem.title= @"我的";
//        mine.tabBarItem.image = [UIImage imageNamed:@"aboutme_unchecked"];
//        mine.tabBarItem.selectedImage = [[UIImage imageNamed:@"aboutme_checke"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//        [((UINavigationController *)tabBarController.selectedViewController) pushViewController:mine animated:YES];
//    }
//}

119 120

@end