iOS中多个storyboard之间的跳转

来源:互联网 发布:怎么学java软件工程师 编辑:程序博客网 时间:2024/06/05 06:09

在iOS开发中,一个工程中可以有多个storyboard,这样可以更方便的进行多人开发以及管理。
实现步骤:

1.新建一个工程,在工程中添加一个storyboard

新建的工程一般都自带一个Main.stroyboard,我们还需要建两一个storyboard,命名为Other.storyboard,
这里写图片描述

2.设置Other.stroyboard

在Other.stroyboard中添加一个ViewController,并把Is Initial View Controller勾选作为启动ViewController,设置背景色,添加label作为标示

这里写图片描述

3.设置Main.storyboard

Main.storyboard默认有一个ViewController,在这个控制器添加一个Button,点击Button触发storyboard跳转,为Button添加出发事件,写下以下代码就完成了

- (IBAction)toOtherStoryboard:(id)sender {    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Other" bundle:nil];    //Other为另一个Storyboard的名字    [UIApplication sharedApplication].keyWindow.rootViewController = storyboard.instantiateInitialViewController;}

这里写图片描述

4.结果

这里写图片描述

1 0