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

接推广网站网站数据库购买

接推广网站,网站数据库购买,上海网站制作与推广,蒙古文网站建设工作情况汇报【iOS】present和push present和push的比较 present和push都用于iOS的视图切换,并且切换都是可逆的,原始视图不会被销毁,还可以直接更改window的rootViewController来切换视图,但是这种方法不可逆,并且原始视图会被销毁…

【iOS】present和push

present和push的比较

  1. present和push都用于iOS的视图切换,并且切换都是可逆的,原始视图不会被销毁,还可以直接更改window的rootViewController来切换视图,但是这种方法不可逆,并且原始视图会被销毁

  2. present一般用于不同业务界面的切换,push一般用于同一业务不同界面的切换

  3. present和dismiss对应,push和pop对应

  4. present只能逐级返回,push有栈控制,但是可以返回任意级 ?

push方法

SecondViewController* secondViewController = [[SecondViewController alloc] init];
[self.navigationController pushViewController:secondViewController animated:YES];

pop方法

//返回上一级视图
[self.navigationController popViewControllerAnimated:YES];
//返回根视图
[self.navigationController popToRootViewControllerAnimated:YES];
//返回指定级数
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0]];

这里返回到指定级数的方法,是通过访问视图控制器属性来获得视图控制器数组,在这个数组中可以获得导航控制器的每一层视图,再调用popToViewController方法就可以回到指定级数的视图。

present方法

SecondViewController* secondViewController = [[SecondViewController alloc] init];
[self presentViewController:secondViewController animated:YES completion:nil];

dismiss方法

[self dismissViewControllerAnimated:NO completion:nil];

dismiss多级的方法

两个属性

在讲解dismiss多级视图控制器的方法之前,先来了解一下presentedViewController和presentingViewController这两个UIViewController的属性。

presentedViewController:The view controller that was presented by this view controller or its nearest ancestor. 由这个视图控制器或它最近的祖先呈现的视图控制器 presentingViewController:The view controller that presented this view controller (or its farthest ancestor.) 呈现此视图控制器(或其最远祖先)的视图控制器。

举个例子:如果B控制器是由A控制器present弹出的,那么:

A.presentedViewController = B;

B.presentingViewController = A;

dismiss多级

现在来实现A、B、C、D四个视图控制器通过dismiss来实现多级之间的跳转。假设A、B、C、D四个视图之间的跳转关系为A->B->C->D

由D视图dismiss到A视图

UIViewController *rootViewController = self.presentingViewController;
while (rootViewController.presentingViewController) {rootViewController = rootViewController.presentingViewController;
}
[rootViewController dismissViewControllerAnimated:YES completion:nil];

dismiss两级

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES];

也可以向前遍历来访问要dismiss的视图

UIViewController *ViewController = self.presentingViewController;
while (![ViewController isKindOfClass:[SecondViewController class]]) {ViewController = ViewController.presentingViewController;
}
[ViewController dismissViewControllerAnimated:YES completion:nil];

注意

这里的dismiss与我们以前常用的dismiss用法不同,以前都是被切换出的视图控制器调用dismiss方法来回到上一级视图控制器。而这里却是要回到哪一级视图控制器,就哪一级视图控制器调用dismiss方法。

那么dismissViewController到底在哪里执行呢?

其实,如果由A跳转到B,presentViewController方法在A里面执行,而dismissViewController也是A视图控制器来调用

苹果文档里的一段话: The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller. 翻译如下: 呈现视图控制器负责解散它呈现的视图控制器。如果你在被呈现的视图控制器本身上调用这个方法,它会自动将消息转发给呈现的视图控制器。

什么意思呢?

其实就是如果在B中调用dismiss方法,dismiss方法会自动交给B的presentingViewController(也就是AViewController)来执行。

//在B中返回上一级
[self dismissViewControllerAnimated:NO completion:nil];
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
//这两种写法效果一致

对于在A中执行dismiss从而实现多级跳转到A的解释如下:

苹果文档里的解释 If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack. 翻译如下: 如果你连续展示多个视图控制器,从而构建了一个由被展示的视图控制器组成的堆栈,那么在堆栈中较低位置的视图控制器上调用这个方法,会解除其直接子视图控制器以及该子视图控制器上方堆栈中的所有视图控制器。当这种情况发生时,只有最顶层的视图是以动画方式被解除展示的;任何中间的视图控制器都会直接从堆栈中移除。最顶层的视图使用其模态过渡样式来解除展示,该样式可能与堆栈中较低位置的其他视图控制器使用的样式不同。

也就是说,当present多个视图控制器时,系统维护了一个栈,栈中存放着A、B、C、D四个视图控制器。当在A中执行dismiss方法,栈中在A之上的视图就会被dismiss掉,不同的是,栈顶视图会以动画形式dismiss,而中间的视图控制器只是简单地remove掉。

http://www.yayakq.cn/news/115692/

相关文章:

  • 怎么创建自己公司的网站中国建设银行泗水支行的网站
  • 千博企业网站管理系统2013如何购买已备案域名
  • 织梦dedecms导航网站源码wordpress爆破密码字典
  • 网站右下角图片广告代码wordpress iis 分页 404
  • 网站备案查询站长工具WordPress附件空间
  • 智云鸟网站建设asp.net jsp 网站
  • 沧州网站开发报考大专网站肇庆
  • 宁波海曙区建设局网站网站联盟名词解释
  • 举例说明网络营销的概念如何为网站做seo体检
  • 网站备案工信部北京网站设计套餐
  • 南沙商城网站建设低价网站备案
  • 硅胶鞋垫移动网站建设个体工商户营业执照查询官网
  • 网站规划对网站建设起到什么作用西安seo网站关键词优化
  • 吴江网站开发wordpress 自定义分页
  • 北京专业网站建设服务商春哥技术团队网站建设
  • 那些网站是静态做少儿培训网站的公司
  • 女人被做网站辽宁建设工程信息网上开标流程
  • 外贸网站打开速度小程序页面设计用什么软件
  • 织梦网站默认密码忘记家居装修风格图片大全
  • 广州做企业网站的公司手机浏览器网站开发
  • 阿里云做网站可以免备案吗哪里有建设公司官网
  • 公司网站维护好做吗揭阳新闻最新消息
  • 百货网站建设建设英文网站的申请怎么写
  • 网络营销的形式网站营销烟台网站建设设计开发
  • 国内网站开发的主流技术校园门户网站开发需求分析
  • 太原新站优化网站模版的软件
  • 博客新手wordpress湖南关键词优化品牌推荐
  • 做资讯网站需要什么条件家装设计说明
  • 网站优化要怎么做网站模板 div
  • 关于网站开发的个人小结南宁有做门户网站的公司吗