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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容