viewDidUnload versus viewDidDisappear

2019-02-22 11:41发布

I don't understand when I should implement something in viewDidUnload versus viewDidDisappear. What's the difference between the two?

For instance, I'd like to send an NSNotificaton when the view controller is removed from the view hierarchy. Between these two methods, does it matter where I post that notification from?

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIViewController_Class/Reference/Reference.html

2条回答
狗以群分
2楼-- · 2019-02-22 12:03

This is with reference to apple's documentation:-

viewDidUnload:-

When a low-memory condition occurs and the current view controller’s views are not needed, the system may opt to remove those views from memory. This method is called after the view controller’s view has been released and is your chance to perform any final cleanup. If your view controller stores separate references to the view or its subviews, you should use this method to release those references. You can also use this method to remove references to any objects that you created to support the view but that are no longer needed now that the view is gone.

viewDidDisappear:-

Notifies the view controller that its view was removed from a view hierarchy that is everytime view dissapears or move to other view.

查看更多
Summer. ? 凉城
3楼-- · 2019-02-22 12:11

viewDidDisappear is called every time when the view is disappears or you go to other view and viewDidUnload is called when the controller’s view is released from memory. (Deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.) see the reference.

查看更多
登录 后发表回答