What new in storyboard 新特性

  1. 如何去使用 storyboard reference

如果你想将厚重的 Main.storyboard 中的 ViewController 分离出来,单独使用一个 StoryBoard。那么 Stroyboard Reference 将会派上用场。

基本使用方法:

1. 在故事版中选择你想要分离出来的 ViewController
2. 在菜单栏中选择 editor -> refactor to storyBoard  
3. 在弹窗中修改你的 Storyboard 名称 跟保存地址

好的, 就这么简单.

  1. 如何使用 Unwind Segue

    • 首先理解视图控制器的层级关系, presenting ViewController 与 presented ViewController。

      • 原因:当在 unwindSegue 被触发时 我们希望调用此方法
    • 在 presenting ViewController 中添加 @IBAction

        @IBAction func backToThisView(segue: UIStoryboardSegue){
        }
      
    • 在 storyBoard 中选择 presented Viewcontroller。按住 Control 拖拽 ViewController Icon 到 Exit Icon. 选择上一步的方法名. 并且在 Xcode 的 Utilites 中选择 Attribute inspector。修改identity属性。 需要通过这个 identify 来找到对应的 unwindSegue。

      • unwindSegue 触发时会让 UIKit 调用相关的方法(我们在第一步添加的 IBAction )
    • 最后一步,在 Presented ViewController 中合适的时机 触发 unwindSegue 方法。

        performSegue(withIdentifier: "identify", sender: self)

你可能感兴趣的:(What new in storyboard 新特性)