gpt4 book ai didi

ios - Root View Controller 偶尔丢失

转载 作者:行者123 更新时间:2023-11-29 12:38:28 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com