面试:StoryBoard

2016-01-19  本文已影响681人  冰J冰

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

知识铺垫

页面跳转(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

上一篇下一篇

猜你喜欢

热点阅读