StoryBoard

作者: 俊月 | 来源:发表于2016-01-21 09:38 被阅读485次

    1.第一个项目用的是xib,一个页面包含3个部分【.h .m .xib】

    2.第二个项目用的是storyboard.
    3.有四个模块,然后我们用了4个storyboard,每个storyboard含有一个NavigationController。
    4.用UITabBarController做这四个storyboard的【container view controller】容器。
    5.最后把UITabBarController 设为window.rootViewController 。

    UITabBarController *tabBar = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateInitialViewController];

    UINavigationController *firstVC = [[UIStoryboard storyboardWithName:@"VCStoryboard" bundle:nil] instantiateInitialViewController];
    
    
    UINavigationController *secondVC = [[UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil] instantiateInitialViewController];
    UINavigationController *thirdVC = [[UIStoryboard storyboardWithName:@"ThirdStoryboard" bundle:nil] instantiateInitialViewController];
    UINavigationController *fourthVc = [[UIStoryboard storyboardWithName:@"Fourth" bundle:nil] instantiateInitialViewController];
    UINavigationController *fifthVc = [[UIStoryboard storyboardWithName:@"Fifth" bundle:nil] instantiateInitialViewController];
    
    tabBar.viewControllers = @[firstVC,secondVC,thirdVC,fourthVc,fifthVc];
    

    self.window.rootViewController = tabBar;

    Paste_Image.png

    知识铺垫
    storyboard 把 view controller叫做:“scene”.(场景)
    storyboard可以描述各种场景之间的过渡,这种过渡被称作"segue",你通过简单的ctrl-dragging就能搞定,减少代码量。
    storyboard支持table view的prototype cell,这意味着你可以在storyboard中编辑cell,直接在tableView 中建立cell 的xib,减少代码量。
    更改初始化vc 【is initial view controller】
    只有给scene 设置 完class ,才可以向对应的.h 或.m 拖拽。
    页面跳转(A页面的button 点击跳转B页面)
    ①在StoryBoard的某个scene中 A页面的button 直接往B页面上拖拽,
    弹出页面,选择跳转方式,就完成了页面的跳转
    ②使用代码进行跳转
    把界面缩小(你可以在空白的地方双击一下,或者右键选择缩放比例)
    把A页面往B页面拖拽,弹出页面,选择跳转方式。此时产生A页面过度到B页面的segue。设置segue 的identifier (唯一标识),在A页面的button 的点击事件下写入代码

    [self performSegueWithIdentifier:@"segueIdentifier" sender:self];
    

    页面传值
    ① 使用- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; 进行传值

    • (IBAction)goAction:(id)sender
      {
      // 根据指定线的ID跳转到目标Vc
      [self performSegueWithIdentifier:@"SendValue" sender:self];
      }

    • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      // segue.identifier:获取连线的ID
      if ([segue.identifier isEqualToString:@"SendValue"]) {
      // segue.destinationViewController:获取连线时所指的界面(VC)
      ReceiveViewController *receive = segue.destinationViewController;
      receive.name = @"Garvey";
      receive.age = 110;
      // 这里不需要指定跳转了,因为在按扭的事件里已经有跳转的代码
      // [self.navigationController pushViewController:receive animated:YES];
      }
      }
      ②通过storyBoard name 获取storyboard;通过storyBoardId 获取对应的VC,然后通过push 的方式进行跳转。

    • (IBAction)action:(id)sender
      {
      // 获取指定的Storyboard,name填写Storyboard的文件名
      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
      // 从Storyboard上按照identifier获取指定的界面(VC),identifier必须是唯一的
      ReceiveViewController *receive = [storyboard instantiateViewControllerWithIdentifier:@"IdReceive"];
      receive.name = @"GC";
      receive.age = 10;
      [self.navigationController pushViewController:receive animated:YES];
      }
      参考:
      http://www.tuicool.com/articles/uuAv2ia
      http://www.jianshu.com/p/2ec2c19f183e

    相关文章

      网友评论

      • 042a0e1be73f:你好,我想问tabBar是用代码自定义的,可以添加Storyboard吗?

      本文标题:StoryBoard

      本文链接:https://www.haomeiwen.com/subject/roulkttx.html