(app.m)
oneViewController *one = [[oneViewController alloc]init];
UINavigationController *oneNav = [[UINavigationControlleralloc]initWithRootViewController:one];
// 子控制器设置标签栏按钮
oneNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"哈哈" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
// oneNav.tabBarItem.badgeValue = @"99+";
twoViewController *two = [[twoViewController alloc]init];
UINavigationController *twoNav = [[UINavigationControlleralloc]initWithRootViewController:two];
twoNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"哈哈" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
threeViewController *three = [[threeViewController alloc]init];
UINavigationController *threeNav = [[UINavigationControlleralloc]initWithRootViewController:three];
threeNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"哈哈" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
// 主控制器 添加子控制器的属性
UITabBarController * tbvVC =[[UITabBarController alloc]init];
tbvVC.viewControllers =@[oneNav,twoNav,threeNav];
self.window.rootViewController =tbvVC;
(导航控制器)
一、导航控制器的一些属性和基本使用
1.把子控制器添加到导航控制器中的四种方法
(1)
1.创建一个导航控制器
UINavigationController *nav=[[UINavigationControlleralloc]init];
2.设置导航控制器为window的根视图
self.window.rootViewController=nav;
3.添加
YYOneViewController *one = [[YYOneViewController alloc] init];
[nav pushViewController:one animated:YES];
(2)
1.创建一个导航控制器
UINavigationController *nav=[[UINavigationControlleralloc]init];
2.设置导航控制器为window的根视图
self.window.rootViewController=nav;
3.添加
YYOneViewController *one = [[YYOneViewController alloc] init];
[nav addChildViewController:one];
(3)
1.创建一个导航控制器
UINavigationController *nav=[[UINavigationControlleralloc]init];
2.设置导航控制器为window的根视图
self.window.rootViewController=nav;
3.添加
YYOneViewController *one = [[YYOneViewController alloc] init];
nav.viewControllers=@[one];(添加到导航控制器的栈中)
说明:nav.viewControllers;== nav.childViewControllers;注意该属性是只读的,因此不能像下面这样写。nav.childViewControllers = @[one];
(4)最常用的方法
YYOneViewController *one=[[YYOneViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:one];
2.当前子控制器界面导航栏的标题以及对应返回标题的设置
self.navigationItem.title=@"第一个界面";
self.navigationItem.backBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"返回一"style:UIBarButtonItemStylePlain target:nilaction:nil];
3.给导航栏添加按钮
说明:可添加一个,也可以添加多个(数组)
添加导航栏左边的按钮(添加一个相机图标的按钮),会盖掉返回
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
4.界面跳转
跳转到第二个界面(当前为第三个,移除当前栈顶的控制器) [self.navigationControllerpopViewControllerAnimated:YES];
移除处理栈底控制器之外的所有控制器 [self.navigationControllerpopToRootViewControllerAnimated:YES];
只要传入栈中的某一个控制器,就会跳转到指定控制器 [self.navigationController popToViewController:<#(UIViewController *)#> animated:<#(BOOL)#>];
摘自。
网友评论