didMoveToWindow: How will this method be called?

2019-09-04 20:03发布

问题:

I spent time searching this without much success (including documentation), still left puzzled the didMoveToWindow: method.

Using didMoveToWindow: in a stock view project template:

-(void)didMoveToWindow{

    [super didMoveToWindow];

    // do something

}

gives the following warning:

Warning: 'UIViewController' may not respond to 'didMoveToWindow'

It is not called on start up of view which is a surprise.
How will this method be called?

回答1:

didMoveToWindow is a method of UIView, not UIViewController.



回答2:

In a UIViewController, you probably want viewDidAppear.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/viewDidAppear:



标签: ios xcode uiview