storyBoard使用介绍

storyBoard使用介绍

转载地址:http://www.2cto.com/kf/201210/161737.html

一 、简述

Storyboard是你可以用来定义用户界面的一种新的方式,像xib。
与xib不同的是它可以同时管理多个ViewController,而且可以在Storyboard中配置ViewController 之间的跳转关系。

二、 Scene之间的数据传递

当你从当前 scene中触发一个segue的时候,系统会自动调用prepareForSegue:sender:这个方法。如果你想从一个界面切换到里另一个界面的时候传递数据,你应该override这个方法。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"The segue id is %@", segue.identifier );
    UIViewController *destination = segue.destinationViewController;  
    if ([destination respondsToSelector:@selector(setData:)])
    {
        [destination setValue:@"这是要传递的数据" forKey:@"data"];
    }   
}

三、ViewController之间的跳转

  1. 如果在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。
  2. 如果目标ViewController存在Storyboard中,但是没有segue。你可以通过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,然后再用你想要的方式实现跳转,如:压栈。
  3. 如果目标ViewController不存在,那就去创建它吧。

四、获取storyBoard和初始化storyBoard中某个viewController

UIStoryboard *secondStoryboard = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
[storyboard instantiateViewControllerWithIdentifier"actionList"];   
posted @ 2015-07-28 16:36  AbeDay  阅读(401)  评论(0编辑  收藏  举报