UINavigationController总结


UIBarItem: 1.UIBarButtonItem;2.UITabBarItem


UIView: 1.UINavigationBar、UIToolBar、UITabBar

UIResponder: 1.UIViewController、UITabBarController、UINavigationController



UITabBarController结构:UITabBar、Custom content、Tab bar controller View;UITabBar 控制多个Tab,每个Tab的对象是UIViewController,每个Tab是UITabBarItem的对象

UINavigationController的层次结构:Navigation bar、Navigation toolbar、Custom content


QYTabBarViewController如何控制UIViewController

方法1

//创建3个viewController数组

-(void)bindViewController{

    UIViewController *firstVC = [[UIViewControlleralloc] init];

    firstVC.view.backgroundColor = [UIColorredColor];

    UIViewController *secondVC = [[UIViewControlleralloc] init];

    secondVC.view.backgroundColor = [UIColorgreenColor];

    UIViewController *thirdVC = [[UIViewControlleralloc] init];

    thirdVC.view.backgroundColor = [UIColorblueColor];

    UIViewController *fourthVC = [[UIViewControlleralloc] init];

    fourthVC.view.backgroundColor = [UIColororangeColor];    

   NSArray *viewControllers = [NSArrayarrayWithObjects:firstVC,secondVC,thirdVC, fourthVC,nil];

   self.viewControllers = viewControllers;

}

//uiButton添加监听事件

UIButton *barItem = [UIButtonbuttonWithType:UIButtonTypeCustom];

//self 是 要调用action 的对象

[barItem addTarget:selfaction:@selector(changeViewController:)forControlEvents:UIControlEventTouchUpInside];

//根据tag值 在viewControllers 取出 一个视图控制器

-(void)changeViewController:(UIButton *)sender{

   self.selectedIndex = sender.tag -100;

}


方法2

//_window 的根视图控制器 是 tabBarController

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

  UIWindow *window = [[UIWindowalloc] initWithFrame:[UIScreenmainScreen].bounds];

    window.hidden =NO;

   _window = window;

  QYFirstViewController *firstVC = [[QYFirstViewControlleralloc]init]; 

   UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:firstVC];

    QYSecondViewController *secondVC = [[QYSecondViewControlleralloc] init];

    QYThirdViewController *thirdVC = [[QYThirdViewControlleralloc] init];


    UITabBarController *tabBarController = [[UITabBarControlleralloc] init];    


   NSArray *vcs = [NSArrayarrayWithObjects:nav,secondVC,thirdVC, nil];


    tabBarController.viewControllers = vcs;

   _window.rootViewController = tabBarController;


}

//点击btn后,self将调用vcVC视图控制器

QYFirstViewController.m

- (void)viewDidLoad {

UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];

 [btn addTarget:selfaction:@selector(next:)forControlEvents:UIControlEventTouchUpInside];

}

-(void)next:(UIButton *)sender{

    ViewController *vcVC = [[ViewControlleralloc] init];

    [self.navigationControllerpushViewController:vcVC animated:YES];

}


@implementation QYFirstViewController


-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

   if (self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

        

        //创建一个tabBarItem

        UITabBarItem *tabBarItem = [[UITabBarItemalloc] initWithTabBarSystemItem:UITabBarSystemItemTopRatedtag:1];

        //tabBarItem设置成当前视图控制器在tabBarController里显示的tab

       self.tabBarItem = tabBarItem;

       //设置徽章

//        self.tabBarItem.badgeValue = @"10";

    }

    return self;

}


@end
































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值