iOS中push和present的区别

  • push和present都可以推出新的界面
    present和dismiss对应使用,push和pop对应使用
    需要注意的一点是:present只能逐级返回,而push所有视图都由视图栈控制,可以返回上一级,也可以返回到根视图控制器或者其他控制器。
  • 在开发过程中,经常会遇到两个视图控制器的转换。而导航控制器是最常用的一种,这里简单介绍一下push和present的使用和区别吧
  • 1、使用使用UINavigationController时使用push方法: 例如:[self.navigationController pushViewController:xxx animated:NO];
    返回时用pop: 例如:[self.navigationController popViewControllerAnimated:NO];
    2、其他时候用present方法: 例如:[self presentViewController:xxx animated:NO completion:nil]; ;
    返回时用dismiss: 例如:[self dismissViewControllerAnimated:NO completion:nil];

present和dismiss

//present
//进入下一个视图
NextViewController *next = [[NextViewController alloc] init];
 
    [self presentViewController:next animated:YES completion:nil];
//dismiss
//返回上一视图
	[self dismissViewControllerAnimated:NO completion:nil];

push和pop

	//push
	//进入下一视图
	NextViewController *next = [[NextViewController alloc] init];
    [self.navigationController pushViewController:next animated:YES];
	//返回上一视图
	[self.navigationController popViewControllerAnimated:YES];

	//返回根视图(to root)
	[self.navigationController popToRootViewControllerAnimated:YES];

	//返回任意视图(atindex后加返回的层数)
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值