ios - Root View Controller 偶尔丢失

标签 ios ios7

有时,我的应用启动时出现黑屏,并出现以下警告:

Application windows are expected to have a root view controller at the end of application launch

我使用 Storyboard。当我编译应用程序时,这往往会不时随机发生,并且只有在我更改代码和/或 Storyboard然后重新编译时,错误才会消失。 错误的编译将继续以错误的状态启动应用程序,即使您重新启动它也是如此。

应用程序本身(对我来说)唯一不寻常的地方是它的初始 View 包含一个 map View ,上面有多个容器 View (在启动时隐藏)。

我试过使用 Spark Inspector发生这种情况时调试 View 层次结构,它表明唯一的元素是 UIWindow,根本没有加载任何 UIView。

这是我的 didFinishLaunchingWithOptions(这是应用程序委托(delegate)中唯一包含代码的方法),如 Matt 所要求的:

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [DDLog addLogger:[DDASLLogger sharedInstance]];
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];
    UIColor *pink = [UIColor colorWithRed:(118 / 255.0)
                                    green:(214 / 255.0)
                                     blue:(84 / 255.0)
                                    alpha:1.0];
    [[DDTTYLogger sharedInstance] setForegroundColor:pink
                                     backgroundColor:nil
                                             forFlag:LOG_FLAG_INFO];

    #ifdef DEBUG
        DDLogInfo(@"Launching in debug mode");
    #else
        DDLogWarn(@"Launching in release mode");
    #endif

    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
    [[AFNetworkActivityLogger sharedLogger] startLogging];

    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
        setFont:[UIFont fontWithName:@"OpenSans" size:14]];

    NSMutableDictionary *titleBarAttributes = [NSMutableDictionary
        dictionaryWithDictionary:
            [[UINavigationBar appearance] titleTextAttributes]];
    [titleBarAttributes setValue:[UIFont fontWithName:@"OpenSans" size:18]
                          forKey:NSFontAttributeName];
    [[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];

    return YES;
}

最佳答案

如果你正在使用 Storyboard,你可以从 Storyboard设置 Root View Controller enter image description here

否则您必须在 AppDelegate 中以编程方式创建它

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UINavigationController *rootViewController = [[UINavigationController alloc] initWithNibName:@"RootVC" bundle:nil];
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
    return YES;
}

关于ios - Root View Controller 偶尔丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25656998/

相关文章:

ios - 为 iOS 12 开发的应用程序可以安装在 iPadOS 上吗

ios - 解析 : deleting object value in column using Swift

iphone - sprite 套件游戏中的 iAd

IOS7 - performSegueWIthIdentifier 没有任何效果

ios - UIButton 在 IOS 6 中显示默认的带圆角的白色背景,但在 IOS 7 中没有

objective-c - 自定义按钮 titlelabel 文本在点击时将自身设置回默认值

ios - 当应用程序处于非事件状态或在后台时停止当前推送通知

android - 我可以在不使用 Google Play/App Store 的情况下分发 Ionic 应用程序吗?

ios - IOS7中的UIButton背景图片

ios - 嵌套推送动画 iOS7 错误?