博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS present 和 push
阅读量:4143 次
发布时间:2019-05-25

本文共 1338 字,大约阅读时间需要 4 分钟。

文章目录

简介

  • 共同点

    – present和push方法都可用于推出新的界面。 present和dismiss对应使用,push和pop对应使用。

  • 不同点

    – present弹出的视图是模态视图(我对模态视图的理解大概就是一个临时视图);push由视图栈控制,每一个视图都入栈,调用之前的视图则需要出栈
    – present只能逐级返回;push可返回任意一层

使用方法

  • 使用UINavigationController时使用push方法: 例如:[self.navigationController pushViewController:xxx animated:NO];

    返回时用pop: 例如:[self.navigationController popViewControllerAnimated:NO];

  • 其他时候用present方法: 例如:[self presentViewController:xxx animated:NO completion:nil]; ;

    返回时用dismiss: 例如:[self dismissViewControllerAnimated:NO completion:nil];

A视图 present 到 B视图再push到 C视图

为了在B视图里能push,我给B视图创建了一个导航栏,A视图 present进去

A视图按钮的点击事件:

- (void)pass {
NSLog(@"press1"); FirstViewController *first = [[FirstViewController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:first]; [self presentViewController:nav animated:NO completion:nil];}

B视图push到C视图

B视图按钮的点击事件:

- (void)pass {
NSLog(@"press2"); SecondViewController *second = [[SecondViewController alloc] init]; [self.navigationController pushViewController:second animated:NO];}

C视图使用dismiss返回

- (void)back {
NSLog(@"back"); [self dismissViewControllerAnimated:NO completion:nil];}

C视图:

在这里插入图片描述
点击back后:
在这里插入图片描述
直接返回到了A视图!

C视图使用pop返回

- (void)back {
NSLog(@"back"); [self.navigationController popViewControllerAnimated:NO];}

点击back后:

在这里插入图片描述
则返回到了B视图!

转载地址:http://owkti.baihongyu.com/

你可能感兴趣的文章
常用js收集
查看>>
如何防止sql注入
查看>>
springmvc传值
查看>>
在Eclipse中查看Android源码
查看>>
Android使用webservice客户端实例
查看>>
[转]C语言printf
查看>>
C 语言 学习---获取文本框内容及字符串拼接
查看>>
C 语言学习 --设置文本框内容及进制转换
查看>>
C 语言 学习---判断文本框取得的数是否是整数
查看>>
C 语言 学习---ComboBox相关、简单计算器
查看>>
C 语言 学习---ComboBox相关、简易“假”管理系统
查看>>
C 语言 学习---回调、时间定时更新程序
查看>>
C 语言 学习---复选框及列表框的使用
查看>>
第十一章 - 直接内存
查看>>
JDBC核心技术 - 上篇
查看>>
一篇搞懂Java反射机制
查看>>
Single Number II --出现一次的数(重)
查看>>
Palindrome Partitioning --回文切割 深搜(重重)
查看>>
对话周鸿袆:从程序员创业谈起
查看>>
Mysql中下划线问题
查看>>