Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当应用程序转到后台时,UIWindow变为空_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 当应用程序转到后台时,UIWindow变为空

Ios 当应用程序转到后台时,UIWindow变为空,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我有一个uitabarcontroller嵌入在UINavigationController中,当应用程序加载时,它显示初始UIViewController,并且self.view.window属性不是NULL 但当我将应用程序置于后台模式,点击应用程序图标,使应用程序处于活动状态时,self.view.window属性为NULL 我在AppDelegate.h@property(非原子,强)UIWindow*窗口中声明了属性 然后我在AppDelegate.m中设置它,就像self.windo

我有一个
uitabarcontroller
嵌入在
UINavigationController
中,当应用程序加载时,它显示初始
UIViewController
,并且
self.view.window
属性不是
NULL

但当我将应用程序置于后台模式,点击应用程序图标,使应用程序处于活动状态时,
self.view.window
属性为
NULL

我在AppDelegate.h
@property(非原子,强)UIWindow*窗口中声明了属性

然后我在AppDelegate.m中设置它,就像
self.window=[[UIWindow alloc]initWithFrame:UIScreen.mainScreen.bounds]-(BOOL)应用程序中的code>:(UIApplication*)应用程序使用options:(NSDictionary*)launchOptions
方法完成了启动

然后我有了
[self.windowsetRootViewController:launchViewController]
[self.window makeKeyAndVisible]方法


你知道为什么会这样吗?

self.view.window
只有在self.view位于前台时才能访问

作为财产

@property(可空、非原子、只读)UIWindow*窗口


属于层次结构接口
@interface UIView(UIViewHierarchy)

它是一个弱属性吗?确保在didfishlaunchingmethod中有这些代码行,self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds];self.window.rootViewController=您的ViewController;[self.window makeKeyAndVisible];我有所有这些方法。我没有在interface builder中设置
initialViewController
,因为我是通过编程实现的self.window=[[UIWindow alloc]initWithFrame:UIScreen.mainScreen.bounds]
我注册了
uiapplicationidbecomeactivityfication
,因此我认为该视图位于前台。将其命名为self.window1,例如,它不工作。问题是,如果我转到
UITabBarController
中的另一个视图,然后再次返回初始视图,则属性再次正常。现在我注意到,只有在第一次运行应用程序时才会发生这种情况。当我再次从Xcode运行应用程序时,一切都正常。我可以使用您需要访问
self.view.window的用例吗