Container View Controllers inside of a UINavigationController don't properly get restored during State Restoration
| Originator: | michael.mcguire | ||
| Number: | rdar://19160992 | Date Originated: | 12/5/2014 |
| Status: | Closed | Resolved: | Yes |
| Product: | iOS SDK | Product Version: | 8.0 |
| Classification: | Open | Reproducible: | Yes |
Summary: When a view controller hierarchy has a depth of more than 1 container view controller inside of a UINavigationController, only the top most container view controller is properly restored (i.e. decodeRestorableStateWithCoder: is called). The attached sample project has several configurations that demonstrate the problem. In the AppDelegate.m, there are six different example hierarchies created, with the last two (#5 and #6) not working properly. In all cases, all of the view controllers involved in the hierarchy get encoded into the state preservation data (checked using logging statements and the restorationArchiveTool provided by Apple), but in the last two examples not all of the view controllers are properly restored. Using logging statements, you can see that the decodeRestorableStateWithCoder: method is not called on all of the view controllers, which causes the tab bar to lose its selected view controller and restore back to the first tab. Steps to Reproduce: 1) Uncomment one of the scenarios in the AppDelegate.m, make sure all of the other scenarios are commented. 2) Run the application in Xcode 3) Switch to the second tab 4) Press the home button to kick off the state preservation process 5) Quit the application by stopping in Xcode 6) Run the application again in Xcode 7) Note that in examples 1-4, the second tab is still selected, but in examples 5-6, the tab bar changes back to the first tab. 8) Delete the application from the device 9) Repeat steps 1-7 for all of the examples. Expected Results: All 6 of the examples should properly restore the application so the second tab is still selected. Actual Results: The final two examples are not properly restored. The first tab is selected instead. Version: 8.0.2 (12A405) Notes: I have subclassed UINavigationController and UITabController only to log the calls to encodeRestorableStateWithCoder: and decodeRestorableStateWithCoder:(NSCoder *)coder. Using actual UINavigationController and UITabController gets the same results. Configuration: iPhone 6, AT&T Update: This is by design: you need to make reference to child view controllers inside of custom container controllers. See: http://mikeabdullah.net/thl-diary-20-restore-container-vc.html
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!
Demo code: https://github.com/MichaelMcGuire/UINavigationControllerStateRestorationBug