[英]UIWindow loses rootviewcontroller after launch
My application has a UIWindow with a correctly set rootview controller. 我的应用程序有一个带有正确设置的rootview控制器的UIWindow。 I know this because I check for the rootViewController after it is set (in the app delegate), and all is well.
我知道这一点是因为我在设置了它之后(在应用程序委托中)检查了rootViewController,一切都很好。
Once My app launches, everything works fine. 我的应用启动后,一切正常。 My issue is that the rootview controller is no longer set correctly on the UIWindow when I check in the 'main' view.
我的问题是,当我在“主”视图中签入时,rootview控制器在UIWindow上的设置不再正确。
My app works fine.. so what is the issue you may be wondering... well, I am trying to implement AdColony (video advertising), an they need to grab the UIWindow's rotviewcontroller to dislplay their ad. 我的应用程序正常运行..所以您可能想知道的问题是...我正在尝试实现AdColony(视频广告),他们需要抓住UIWindow的rotviewcontroller来展示广告。 When they check for the rootviewcontroller... it is null.
当他们检查rootviewcontroller ...时为null。
I have added code to check as well.. and the rootviewcontroller is null. 我也添加了要检查的代码..而rootviewcontroller为null。
How can my UIWindow lose its pointer to the rootviewcontroller? 我的UIWindow如何丢失指向rootviewcontroller的指针? I need help understanding how the UIWindow architecture works.
我需要帮助来了解UIWindow体系结构的工作方式。
Thanks 谢谢
code that checks for UIWindow's visible controller (the below code returns nil for the viewcontrollers value. 检查UIWindow的可见控制器的代码(以下代码为viewcontrollers值返回nil。
UIWindow* window = [UIApplication sharedApplication].keyWindow;
UIViewController* rootViewController = [window rootViewController];
[self getVisibleViewControllerChild:rootViewController];
- (UIViewController*)getVisibleViewControllerChild:(UIViewController*)viewController {
UIViewController* visibleViewController = nil;
if(!viewController) {
NSLog(@"nil");
return nil;
}
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)viewController;
viewController = navigationController.visibleViewController;
NSLog(@"viewcontroller is nav controller");
}
while (visibleViewController == nil) {
if (viewController.modalViewController == nil) {
visibleViewController = viewController;
NSLog(@"visibleViewController = %@", visibleViewController);
} else {
if ([viewController.modalViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)viewController.modalViewController;
viewController = navigationController.visibleViewController;
NSLog(@"modal 1");
} else {
viewController = viewController.modalViewController;
NSLog(@"modal 2");
}
}
}
return visibleViewController;
} }
I can't really figure out what you're trying to do with this code, but the method keyWindow seems to be returning nil, so rootViewController will also be nil. 我无法真正弄清楚您要使用此代码做什么,但是方法keyWindow似乎返回nil,因此rootViewController也将为nil。 I'm not sure why that's true, but you can get the rootViewController with (I assume you're doing this from a view controller):
我不确定为什么会这样,但是您可以使用rootViewController(我假设您正在从视图控制器执行此操作):
self.view.window.rootViewController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.