视图控制器中之间切换的几种方式 by 李梦珂

**

1.模态视图

**

-(void)presentModel
{
RootViewController *rootview = [[RootViewController alloc]init];

rootview.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:rootview animated:YES completion:^{
    NSLog(@"call back");
}];

}

2,UITabBarController实现并列画面跳转

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

UIViewController *vc1 = [[UIViewController alloc]init];
vc1.title = @"消息";
vc1.view.backgroundColor = [UIColor redColor];
UIViewController *vc2 = [[UIViewController alloc]init];
vc2.title = @"设置";
vc2.view.backgroundColor = [UIColor orangeColor];
UIViewController *vc3 = [[UIViewController alloc]init];
vc3.title = @"主页";
vc3.view.backgroundColor = [UIColor yellowColor];
UIViewController *vc4 = [[UIViewController alloc]init];
vc4.title = @"微博";
vc4.view.backgroundColor = [UIColor greenColor];
UIViewController *vc5 = [[UIViewController alloc]init];
vc5.title = @"图片";
vc5.view.backgroundColor = [UIColor blueColor];

NSArray *controller = @[vc1,vc2,vc3,vc4,vc5];
UITabBarController *tabbar = [[UITabBarController alloc]init];
tabbar.viewControllers = controller;

这里写图片描述
**

3,UINavigationController实现多层画面跳转,在导航控制器中,载入有层级关系的界面

**

-(void)pushNavigation
{
SecondViewController *controller2 = [[SecondViewController alloc]init];
[self.navigationController pushViewController:controller2 animated:YES];
}

-(void)index
{
UIViewController *second = [[self.navigationController viewControllers]objectAtIndex:1];
[self.navigationController popToViewController:second animated:YES];
}
注:UInavigationController中各视图之间有层级关系,用栈的模式来管理视图控制器,而UITabBarController中各视图之间是并列关系,无层级之分。
两者混合使用时最好将UINavigationController加到UITabBarController上!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值