【问题现象】

创建自定义storyboard,添加ViewController之后通过instantiateViewControllerWithIdentifier方法创建ViewController异常。

ios Storyboard doesn't contain a view controller with identifierios Storyboard doesn't contain a view controller with identifier

【问题分析】

原始代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor redColor];
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Window" bundle:nil];
    CTestViewController *t = [storyBoard instantiateViewControllerWithIdentifier:@"CTestViewController"];
    [self.window setRootViewController:t];
    [self.window makeKeyAndVisible];
    return YES;
}

如果创建Singal View Application,则正常。

发现storyboard文件名不能为Window.storyboard,改为其它文件名即可。

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2021-06-11
  • 2021-05-11
  • 2021-06-03
  • 2022-12-23
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-08-15
相关资源
相似解决方案