CS193p 斯坦福IOS开发 2011 (六)

前向引用

@class

多个MVC

一个MVC只能控制一个屏幕,或者更小的区域,随着程序变得越来越复杂,我们会需要多个MVC,那么如何在多个MVC之间进行切换呢?
答案是使用:Controller of Controller : UINavigationController

UINavigationController

  1. 什么是UINavigationController
  • UINavigationController也是继承于UIViewController,不过它是用来控制控制器的控制器。
  • UINavigationController有一个Outlet只向一另外一个MVC,就是它的rootViewController。
  • rootViewController就是出现在白色区域的, 原来的rootViewController放到UINavigationController后,它 的bounds高度会变小一些。
  • UINavigationController通过执行一个segues,可以跳转到另外一个MVC上。就是把新的MVC push都屏幕上,点返回,把当前的MVC pop出来。


    image.png
  1. 如何创建一个UINavigationController


    Screen Shot 2019-01-23 at 11.59.36 AM.png

Segues

  1. segues的三种方式:
  • push
  • modal:Puts the view controller up in a way that blocks the app until it is dismissed
  • custom: You can create your own subclasses of
    UIStoryboardSegue

IPAD ONLY:

  • replace:Replaces the right-hand side of a UISplitViewController
  • Popover - Puts the view controller on the screen in a popover
  1. 如何创建Segues:
    ctrl + 拖拽

  2. 一般是通过用户切换来进行跳转但是有时候也可以通过 segueID在代码里面进行条件跳转

- (void)performSegueWithIdentifier:(NSString *)segueId sender:(id)sender;

例子:

- (IBAction)rentEquipment
{
if (self.snowTraversingTalent == Skiing) {
[self performSegueWithIdentifier:@“AskAboutSkis” sender:self];
} else {
[self performSegueWithIdentifier:@“AskAboutSnowboard” sender:self];
  }
}
  1. 跳转之前准备方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@“DoAParticularThing”]) {
    UIViewController *newController = segue.destinationViewController;
  }
  // send messages to newController to prepare it to appear on screen
  // the segue will do the work of putting the new controller on screen
}
  1. 通过名字从故事版实例化ViewController, 而不是从segue创建
- (IBAction)doit
{
DoitViewController *doit =
[self.storyboard instantiateViewControllerWithIdentifier:@”doit1”];
doit.infoDoitNeeds = self.info;
[self.navigationController pushViewController:doit animated:YES];
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 更好的阅读体验,请到个人博客阅读: iOS中的系统转场 请忽略标题,😂,本文记录的是对下图所示的Kind, Pre...
    CaryaLiu阅读 2,376评论 0 1
  • 1.找到 help --> Install new Software 2.点击添加按钮 3.在输入框中输入: N...
    光脚丫的孩子阅读 1,163评论 0 0