当前位置: 首页 > backend >正文

iOS - present和push

一.定义区别

  1. pushViewController 导航栏控制器入栈的方式切换页面(pop可以返回任意一层)push一般用于同一业务不同界面之间的切换(也就是只能导航栏间的切换,从第二个导航栏到第三个导航栏)
- (void) pass {NSLog(@"pass to third");//第三个同样是导航栏,而且两个导航栏之间可以自由返回ThirdViewController *thirdVC = [[ThirdViewController alloc] init];[self.navigationController pushViewController:thirdVC animated:YES];
}
  1. presentViewController模式切换的方式切换页面(dismiss只能逐级返回)present一般用于不同业务界面的切换。
    若是由视图页面转到导航栏,要先建立一个导航栏。
//出来一个navigationSecondViewController *secondVC = [[SecondViewController alloc] init];UINavigationController *navSecondVC = [[UINavigationController alloc] initWithRootViewController:secondVC];navSecondVC.modalPresentationStyle = UIModalPresentationFullScreen;[self presentViewController:navSecondVC animated:YES completion:nil];

若是两个视图间,直接用present即可

- (void) press {NSLog(@"press 01");SecondViewController *secondVC = [[SecondViewController alloc] init];secondVC.modalPresentationStyle = UIModalPresentationFullScreen;[self presentViewController:secondVC animated:YES completion:nil];
}

二. 返回方法

  1. push和pop对应
    用UINavigationController的时候用pushViewController:animated返回之前的视图[[self navigationController] popViewControllerAnimated:YES]; push以后会在navigation的left bar自动添加back按钮,所以一般不用写返回,点back方法即可
    有关pop,pop一般返回一级和左上角的back的作用是一样的,所以它的用处在于可以分级返回
	//返回上一视图[self.navigationController popViewControllerAnimated:YES];//返回根视图(to root)[self.navigationController popToRootViewControllerAnimated:YES];//返回任意视图(atindex后加返回的层数)[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
  1. present和dismiss对应presentModalViewController:animated
    [self presentModalViewController:controller animated:YES];
    返回之前的视图 [self dismissModalViewControllerAnimated:YES];
    dismiss在导航栏和页面中都可以使用,在页面中即返回上一级页面,在导航栏中使用的话是返回到所有导航栏前的一个页面,但是写法是相同的。
- (void) backDiss {NSLog(@"backdiss");[self dismissViewControllerAnimated:YES completion:nil];
}

三.使用区别

  1. [self presentModalViewController:controller animated:YES];主语是UIVIewController,即单纯页面切换
  2. [self.navigationController pushViewController:upViewController animated:YES];与[self.navigationController popViewControllerAnimated:YES];这两句时主语是navigationController,所以如果是在导航栏上实现页面的跳转使用push,除此之外的都是用present

代码

2020-10-04 23:15:46.330677+0800 present和push[79292:5066460] press 01 to
2020-10-04 23:16:19.915102+0800 present和push[79292:5066460] pass to third
2020-10-04 23:16:42.522594+0800 present和push[79292:5066460] backPop to Second
2020-10-04 23:16:47.412832+0800 present和push[79292:5066460] pass to third
2020-10-04 23:16:48.862871+0800 present和push[79292:5066460] backdiss to First(dissmiss因为上一级页面是第一个,两个导航栏是同一级页面)
2020-10-04 23:17:01.976698+0800 present和push[79292:5066460] press 01 to
2020-10-04 23:17:04.255234+0800 present和push[79292:5066460] pass to four
2020-10-04 23:17:12.925467+0800 present和push[79292:5066460] back2 ?->dissmiss second(因为上一级页面是第二个)
2020-10-04 23:18:01.000129+0800 present和push[79292:5071067] [ServicesDaemonManager] interruptionHandler is called. -[FontServicesDaemonManager connection]_block_invoke

我写的代码,第一个视图present到第二个(导航栏)。第二个push到第三个(导航栏),第三个可以通过dismiss返回到第一个,也可以通过pop回到第二个。第二个还可以present到第四个(一个界面),第四个通过dismiss回到第二个(导航栏)。如下图:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

http://www.xdnf.cn/news/11133.html

相关文章:

  • 低谷才是出成绩
  • xshell5 可用注册码
  • 基于51/STM32单片机多功能智能饮水机 成品 套件 DIY设计 实物+源程序+原理图+仿真+其它资料
  • 2个recordset合并_史上最全!8种办法玩转Excel文字合并,总有一款适合你!
  • 递归算法的时间复杂度
  • 2024最新版Android studio安装入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
  • 大连旅游信息网
  • 蓝桥杯单片机学习(七):矩阵键盘的扫描原理与基本应用
  • 给第一次做渗透项目的新手总结的一些感悟
  • UltraEdit-32 v12.×× 官方中文版注册码
  • 一套非常详细的机房建设装修方案
  • Linux发行版:CentOS、Ubuntu、RedHat、Android、Tizen、MeeGo
  • 关于汽车html网页设计完整版,10个以汽车为主题的网页设计与实现
  • php-CI框架精简版教程 最快上手
  • FLV格式分析
  • Myeclipse 6.5 增加对 JavaEE 6 的支持
  • NOIP 2009 模拟测试总结
  • HTML做一个学校网站(纯html代码)
  • 【转】国外SCI、EI检索期刊
  • 非主流伤感QQ空间日志_享受着自己的那份孤独
  • 智能ABC输入法破解特别版5.23下载 - xp/windows7通用
  • Node详细解释[带你快速入门Node](1)
  • Android TableLayout
  • Qt Quick - 高仿微信局域网聊天 V5 版本
  • MATLAB中mean的用法
  • Android开发十大必备工具(图文)
  • SMO优化算法(Sequential minimal optimization)
  • C++string类的常用方法
  • 麻雀要革命2 第8节:莽撞的麻雀小姐
  • 找不到msvcp110.dll怎么办,msvcp110.dll丢失的5种修复方法