美文网首页iOS 小册
iOS 拖拽实现多个 storyboard 间跳转

iOS 拖拽实现多个 storyboard 间跳转

作者: fuyoufang | 来源:发表于2019-06-27 13:56 被阅读1次

    在 iOS 的开发过程中,可以使用 Stroyboard 来管理多个 ViewController。创建项目的时候,XCode 默认会帮我们生成一个 Main.stroyboard 的文件。我们可以将多个 ViewController 放入一个 Stroyboard 中。但是在一个 Stroyboard 中放入过多的 ViewController 时,会出现很多问题,比如:打开文件的速度慢,多人编辑容易造成冲突,修改的时候难度增加,等等。这时我们就需要将相关的 ViewController 放在一个单独的 Stroyboard 中,也就是将一个 Stroyboard 拆分成多个。

    多个 Stroyboard 中的跳转,我们可以使用代码实现,那如何使用拖拽连线的方式实现呢?

    实现步骤

    1. 在 XCode 已经帮我们创建了一个 Main.storyboard 的基础上,在创建一个 Second.storyboard。
    2. 在 Main.storyboard 的 Storyboard Entry Point 的 ViewController 中创建并约束一个用于跳转到 Button(命名为:Jump To Second Storyboard)

    Storyboard Entry Point 是进入当前 Storyboard 开始的地方,在 XCode 中用蓝色的箭头表示

    image.png
    1. 在 Main.storyboard 中拖拽出一个 Storyboard Reference,设置其 Storyboard 为我们创建的 Second.storyboard。
    image.png
    1. 按住 control 键,从用于跳转的 Button 拖拽到刚创建的 Storyboard Reference 上,选择跳转方式。
    image.png
    1. 在 Second.storyboard 中拖拽出一个 ViewController, 并设置为最初的 ViewController,设置完之后,ViewController 的左边就会多出一个箭头。

    设置 ViewController 的 Is Initial View Controller 属性,也就是设置 Storyboard 的入口(Storyboard Entry Point)。一个 Storyboard 中只能勾选一个 ViewController 的 Is Initial View Controller 属性,也就是只有一个入口 ViewController。

    image.png
    1. 完成,开始运行测试吧。

    相关文章

      网友评论

        本文标题:iOS 拖拽实现多个 storyboard 间跳转

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