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://stackoverflow.com/questions/8924052/present-storyboard-viewcontroller-from-another-viewcontroller

流程

  1. 创建 Empty.storyboard

    1. 在 storyboard 里添加一个 view controller

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

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

  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. 测试结果


Guess you like

Origin blog.csdn.net/yangxuan0261/article/details/113784079