gpt4 book ai didi

ios - 当应用程序进入后台时,UIWindow 变为 NULL

转载 作者:行者123 更新时间:2023-11-29 12:00:57 24 4
gpt4 key购买 nike

我在 UINavigationController 中嵌入了一个 UITabBarController,当应用程序加载时它显示初始 UIViewControllerself.view.window 属性不是 NULL

但是当我将应用程序置于后台模式并点击应用程序图标以使应用程序变为事件状态时,self.view.window 属性为 NULL

我在 AppDelegate.h 中声明了属性 @property (nonatomic, strong) UIWindow *window;

然后我在 AppDelegate.m 中设置它 self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];- (BOOL)application:( UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法。

然后我有 [self.window setRootViewController:launchViewController];[self.window makeKeyAndVisible]; 方法。

知道为什么会这样吗?

最佳答案

self.view.window 只有当 self.view 在前台时才能访问。

作为属性

@property(nullable, nonatomic,readonly) UIWindow *window;

属于Hierarchy接口(interface)@interface UIView(UIViewHierarchy)

关于ios - 当应用程序进入后台时,UIWindow 变为 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37029110/

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