self.view.window只有在DidAppear之后才存在

- (void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];

UIView *v = self.view;

NSLog(@"%@",v);//存在

UIWindow *w = self.view.window;

NSLog(@"%@",w);//nil

UIWindow *ww = [UIApplication sharedApplication].delegate.window;

NSLog(@"%@",ww);//存在

}

- (void)viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

UIView *v = self.view;

NSLog(@"%@",v);//存在

UIWindow *w = self.view.window;

NSLog(@"%@",w);//存在

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

UIView *v = self.view;

NSLog(@"%@",v);//存在

UIWindow *w = self.view.window;

NSLog(@"%@",w);//nil

}

你可能感兴趣的:(self.view.window只有在DidAppear之后才存在)