【问题标题】:loading different storyboard causing error加载不同的故事板导致错误
【发布时间】:2016-08-17 04:57:17
【问题描述】:

我正在尝试加载不同的故事板,但收到此错误应用程序窗口应该在应用程序启动结束时有一个根视图控制器。谁能帮帮我

- (UIStoryboard *)grabStoryboard {

    UIStoryboard *storyboard;

    // detect the height of our screen
    int height = [UIScreen mainScreen].bounds.size.height;

    if (height == 480) {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_4" bundle:nil];
        // NSLog(@"Device has a 3.5inch Display.");
    }
    if(height == 568)
    {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_5" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }
    if(height == 667)
    {
        storyboard = [UIStoryboard storyboardWithName:@"iPhone_6" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }

    if(height == 736)
    {
        storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        // NSLog(@"Device has a 4inch Display.");
    }

    return storyboard;
}

【问题讨论】:

  • 错误几乎肯定出在您的 appdelegate 中的 applicationdidfinishlaunching 函数中。也发一下
  • 附带说明,您确实没有理由为每个 iPhone 屏幕尺寸加载不同的故事板。自动布局和大小类可以以更优雅、更易于管理的方式处理...

标签: ios objective-c uistoryboard appdelegate


【解决方案1】:

您收到此错误是因为编译器看到您的函数可以返回未初始化的故事板变量的情况。如果没有一个 if 语句为真,则可能会发生这种情况。所以最好重写这个函数,让它总是返回初始化的故事板变量。我的建议是改变如何确定设备型号的方式。看看这个post 以获得提示。

【讨论】:

    【解决方案2】:

    我认为您的一个或多个故事板没有入口点,请确保全部验证。你可以在这里查看官方文档entry point for storyboard

    【讨论】:

      猜你喜欢
      • 2014-06-15
      • 1970-01-01
      • 2022-12-17
      • 2014-03-30
      • 2012-07-31
      • 1970-01-01
      • 2015-11-08
      • 2017-04-01
      • 1970-01-01
      相关资源
      最近更新 更多