ios-自定义Storyboard与UIViewController


title: ios-自定义Storyboard与UIViewController
categories: Ios
tags: [ios, Storyboard, UIViewController]
date: 2021-02-10 15:52:42
comments: false
mathjax: true
toc: true

ios-自定义Storyboard与UIViewController


前篇

  • Present storyboard ViewController from another ViewController - https://*.com/questions/8924052/present-storyboard-viewcontroller-from-another-viewcontroller

流程

  1. 创建 Empty.storyboard

    ios-自定义Storyboard与UIViewController

    1. 在 storyboard 里添加一个 view controller

      ios-自定义Storyboard与UIViewController

  2. 创建 EmptyViewController 类, 用来绑定 Empty.storyboard 相关事件.

    ios-自定义Storyboard与UIViewController

  3. 绑定 sotryboard 和 EmptyViewController 类, 并指定 storyboard 的 identity, 如: sid_empty

    ios-自定义Storyboard与UIViewController

  4. 代码显示.

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Empty" bundle:nil]; // 不需要带 .storyboard 后缀, 否则闪退
    EmptyViewController *evc = [storyboard instantiateViewControllerWithIdentifier:@"sid_empty"]; // 一定要和 storyboard 中设置的一致, 否则闪退
    [[UIApplication sharedApplication].windows[0].rootViewController presentViewController:evc animated:YES completion:nil];
    
  5. 测试结果

    ios-自定义Storyboard与UIViewController


上一篇:【转】Controller以及View的几种创建方式


下一篇:loadView、viewDidLoad及viewDidUnload的关系