willMoveToParentViewController not called by UINavigationController when setting its view controllers

Originator:RichWChan
Number:rdar://18002763 Date Originated:13-Aug-2014
Status:Open Resolved:
Product:iOS SDK Product Version:7.1
Classification:Serious Bug Reproducible:Always
 
Sample code:
https://www.dropbox.com/s/xxx9pkagnd3gbri/DBAppDelegate.m.txt?dl=0

Summary:
The top view controller on the stack of a UINavigationController will not get invoked with the `willMoveToParentViewController:` or `didMoveToParentViewController:` methods when the navigation controller's `setViewControllers:animated:` method is called.

According to the docs for `willMoveToParentViewController:`:

"If you are implementing your own container view controller, it must call the willMoveToParentViewController: method of the child view controller before calling the removeFromParentViewController method, passing in a parent value of nil."

It seems to indicate that child view controllers will have their willMoveToParentViewController: method invoked when they are removed from their parent container view controller, but this strangely does not seem to be the case for UINavigationControllers.

Steps to Reproduce:
1. Create a UINavigationController (`nav`) with a few view controllers in the stack, e.g. `@[ vc1, vc2, vc3 ]`.
2. Call `[nav setViewControllers:@[ someOtherVc ] animated:YES]`.
3. Note that the `willMoveToParentViewController:` and `didMoveToParentViewController:` are only called on `vc1` and `vc2`, but not the top view controller `vc3`.


Expected Results:
All original view controllers to be called with the `*MoveToParentViewController:` methods.

Actual Results:
Only the non-top view controllers are called with the `willMoveToParentViewController:` and `didMoveToParentViewController:` methods.

Version:
iOS 7.1 (11D167)

Notes:
Also confirmed that this exists with the current beta of iOS 8 (Beta 5).



Configuration:
iPhone 5 and iPad Air

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!