Objective - C UITabbarController



//

//  RootViewController.m

//  UI_12day_UITabbarController

//

//  Created by dllo on 15/12/23.

//  Copyright © 2015 dllo. All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>


@property(nonatomic,retain)NSMutableArray *arr;

@property(nonatomic,retain)UITableView *tableView;


@end


@implementation RootViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    

    self.view.backgroundColor = [UIColor cyanColor];

    self.title = @"第一页";

    

    self.arr = [NSMutableArray arrayWithObjects:@"宋江"@"卢俊义"@"吴用"@"公孙胜"@"关胜"@"林冲"@"秦明" ,@"呼延灼" , @"花荣",@"柴进"@"李应"@"朱仝",@"鲁智深",@"武松"@"徐宁"@"张清"@"杨志"@"董平"@"索超"@"戴宗"@"刘唐"@"李逵"@"史进"@"穆弘"@"雷横"@"李俊",nil];

    self.tableView = [[UITableView allocinitWithFrame:CGRectMake(00self.view.frame.size.widthself.view.frame.size.height - 64 - 49style:UITableViewStylePlain];

    self.tableView.dataSource = self;

    self.tableView.delegate = self;

    [self.view addSubview:self.tableView];

    [_tableView release];

    

    // 导航视图不透明

    self.navigationController.navigationBar.translucent = NO;

    

    // 另一个Cell方式

    // tableView的对cell的注册

    [self.tableView registerClass:[UITableViewCell classforCellReuseIdentifier:@"reuse"];

}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return self.arr.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    

    // 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];

    cell.textLabel.text = self.arr[indexPath.row];

    

    return cell;

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end




///


AppDelegate.m

#import "AppDelegate.h"

#import "RootViewController.h"

#import "SecondViewController.h"

#import "ThirdViewController.h"

#import "FouthViewController.h"

#import "FifthViewController.h"

#import "SixthViewController.h"


// 签协议

@interface AppDelegate ()<UITabBarControllerDelegate>


@end


@implementation AppDelegate



- (void)dealloc

{

    [_window release];

    [super dealloc];

}



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   

    self.window = [[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    

    

    RootViewController *rootVC = [[RootViewController allocinit];

    // navigation用来管理viewController

    UINavigationController *naVC = [[UINavigationController allocinitWithRootViewController:rootVC];

       

    // tabbarController来管理navigation

    // 创建一个tabbar的按钮内容,一个按钮对应一个navigation

    naVC.tabBarItem = [[[UITabBarItem allocinitWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000autorelease];

    // 显示消息计数

    naVC.tabBarItem.badgeValue = @"+99";

    

    

    // 创建第二个naVC

    SecondViewController *secVC = [[SecondViewController allocinit];

    UINavigationController *secNAVC = [[UINavigationController allocinitWithRootViewController:secVC];

    secNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"contect" image: [UIImage imageNamed:@"name.png"]tag:1001];

    

    

    // 创建第三个naVC

    ThirdViewController *thirdVC = [[ThirdViewController allocinit];

    UINavigationController *thirdNAVC = [[UINavigationController allocinitWithRootViewController:thirdVC];

    thirdNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"selectedImage:[UIImage imageNamed:@"time.png"]];

    

    

    

    // 创建第四个

    FouthViewController *fouthVC = [[FouthViewController allocinit];

    UINavigationController *fouthNAVC = [[UINavigationController allocinitWithRootViewController:fouthVC];

    fouthNAVC.tabBarItem = [[[UITabBarItem allocinitWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003autorelease];

    

    

    // 创建第五个

    FifthViewController *fifVC = [[FifthViewController allocinit];

    UINavigationController *fifthNAVC = [[UINavigationController allocinitWithRootViewController:fifVC];

    fifthNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"tag:1004];

    

    

    

    // 创建第六个

    SixthViewController *sixVC = [[SixthViewController allocinit];

    UINavigationController *sixNAVC = [[UINavigationController allocinitWithRootViewController:sixVC];

    sixNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"selectedImage:[UIImage imageNamed:@"2.jpg"]];

    

    

    // 创建tabbarController

    UITabBarController *tabVC = [[UITabBarController allocinit];

    // 设置tabVC管理的naVC

    tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];

    // 设置window的根视图控制器

    self.window.rootViewController = tabVC;

    

    // 设置代理人

    tabVC.delegate = self;

 

    

    [tabVC release];

    

    [naVC release];

    [rootVC release];

    

    [secNAVC release];

    [secVC release];

    

    [thirdNAVC release];

    [thirdVC release];

    

    [fouthNAVC release];

    [fouthVC release];

    

    [fifthNAVC release];

    [fifVC release];

    

    [sixNAVC release];

    [sixVC release];

    

    

    // 设置一下tabbar的外观

    // 修改点击后图标颜色,默认点击为蓝色

    tabVC.tabBar.translucent = NO;

    tabVC.tabBar.tintColor = [UIColor brownColor];

    // 修改bar背景颜色

    tabVC.tabBar.barTintColor = [UIColor cyanColor];

    return YES;

}


#pragma mark 这个方法相当于tab的点击方法


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{


    NSLog(@"14111");

    // 通过点击,把显示消息的数字取消

    viewController.tabBarItem.badgeValue = nil;

}












//

//  RootViewController.m

//  UI_12day_UITabbarController

//

//  Created by dllo on 15/12/23.

//  Copyright © 2015 dllo. All rights reserved.

//


#import "RootViewController.h"


@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>


@property(nonatomic,retain)NSMutableArray *arr;

@property(nonatomic,retain)UITableView *tableView;


@end


@implementation RootViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    

    self.view.backgroundColor = [UIColor cyanColor];

    self.title = @"第一页";

    

    self.arr = [NSMutableArray arrayWithObjects:@"宋江"@"卢俊义"@"吴用"@"公孙胜"@"关胜"@"林冲"@"秦明" ,@"呼延灼" , @"花荣",@"柴进"@"李应"@"朱仝",@"鲁智深",@"武松"@"徐宁"@"张清"@"杨志"@"董平"@"索超"@"戴宗"@"刘唐"@"李逵"@"史进"@"穆弘"@"雷横"@"李俊",nil];

    self.tableView = [[UITableView allocinitWithFrame:CGRectMake(00self.view.frame.size.widthself.view.frame.size.height - 64 - 49style:UITableViewStylePlain];

    self.tableView.dataSource = self;

    self.tableView.delegate = self;

    [self.view addSubview:self.tableView];

    [_tableView release];

    

    // 导航视图不透明

    self.navigationController.navigationBar.translucent = NO;

    

    // 另一个Cell方式

    // tableView的对cell的注册

    [self.tableView registerClass:[UITableViewCell classforCellReuseIdentifier:@"reuse"];

}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return self.arr.count;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    

    // 新的Cell方式:用系统的Cell无法加视图,必须通过自定义Cell使用

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];

    cell.textLabel.text = self.arr[indexPath.row];

    

    return cell;

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}



@end




///


AppDelegate.m

#import "AppDelegate.h"

#import "RootViewController.h"

#import "SecondViewController.h"

#import "ThirdViewController.h"

#import "FouthViewController.h"

#import "FifthViewController.h"

#import "SixthViewController.h"


// 签协议

@interface AppDelegate ()<UITabBarControllerDelegate>


@end


@implementation AppDelegate



- (void)dealloc

{

    [_window release];

    [super dealloc];

}



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

   

    self.window = [[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    

    

    RootViewController *rootVC = [[RootViewController allocinit];

    // navigation用来管理viewController

    UINavigationController *naVC = [[UINavigationController allocinitWithRootViewController:rootVC];

       

    // tabbarController来管理navigation

    // 创建一个tabbar的按钮内容,一个按钮对应一个navigation

    naVC.tabBarItem = [[[UITabBarItem allocinitWithTabBarSystemItem:UITabBarSystemItemSearch tag:1000autorelease];

    // 显示消息计数

    naVC.tabBarItem.badgeValue = @"+99";

    

    

    // 创建第二个naVC

    SecondViewController *secVC = [[SecondViewController allocinit];

    UINavigationController *secNAVC = [[UINavigationController allocinitWithRootViewController:secVC];

    secNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"contect" image: [UIImage imageNamed:@"name.png"]tag:1001];

    

    

    // 创建第三个naVC

    ThirdViewController *thirdVC = [[ThirdViewController allocinit];

    UINavigationController *thirdNAVC = [[UINavigationController allocinitWithRootViewController:thirdVC];

    thirdNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"定位" image:[UIImage imageNamed:@"dingwei.png"selectedImage:[UIImage imageNamed:@"time.png"]];

    

    

    

    // 创建第四个

    FouthViewController *fouthVC = [[FouthViewController allocinit];

    UINavigationController *fouthNAVC = [[UINavigationController allocinitWithRootViewController:fouthVC];

    fouthNAVC.tabBarItem = [[[UITabBarItem allocinitWithTabBarSystemItem:UITabBarSystemItemFavorites tag:1003autorelease];

    

    

    // 创建第五个

    FifthViewController *fifVC = [[FifthViewController allocinit];

    UINavigationController *fifthNAVC = [[UINavigationController allocinitWithRootViewController:fifVC];

    fifthNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"时间" image:[UIImage imageNamed:@"time.png"tag:1004];

    

    

    

    // 创建第六个

    SixthViewController *sixVC = [[SixthViewController allocinit];

    UINavigationController *sixNAVC = [[UINavigationController allocinitWithRootViewController:sixVC];

    sixNAVC.tabBarItem = [[UITabBarItem allocinitWithTitle:@"通知" image:[UIImage imageNamed:@"1.jpg"selectedImage:[UIImage imageNamed:@"2.jpg"]];

    

    

    // 创建tabbarController

    UITabBarController *tabVC = [[UITabBarController allocinit];

    // 设置tabVC管理的naVC

    tabVC.viewControllers = @[naVC,secNAVC,thirdNAVC,fouthNAVC,fifthNAVC,sixNAVC];

    // 设置window的根视图控制器

    self.window.rootViewController = tabVC;

    

    // 设置代理人

    tabVC.delegate = self;

 

    

    [tabVC release];

    

    [naVC release];

    [rootVC release];

    

    [secNAVC release];

    [secVC release];

    

    [thirdNAVC release];

    [thirdVC release];

    

    [fouthNAVC release];

    [fouthVC release];

    

    [fifthNAVC release];

    [fifVC release];

    

    [sixNAVC release];

    [sixVC release];

    

    

    // 设置一下tabbar的外观

    // 修改点击后图标颜色,默认点击为蓝色

    tabVC.tabBar.translucent = NO;

    tabVC.tabBar.tintColor = [UIColor brownColor];

    // 修改bar背景颜色

    tabVC.tabBar.barTintColor = [UIColor cyanColor];

    return YES;

}


#pragma mark 这个方法相当于tab的点击方法


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{


    NSLog(@"14111");

    // 通过点击,把显示消息的数字取消

    viewController.tabBarItem.badgeValue = nil;

}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值