UIViewControllerRestoration Protocol Reference
Available in iOS 6.0 and later.
UIViewControllerRestoration protocol should be adopted by classes that act as "restoration classes” for view controllers during the state restoration process. The method in this protocol should be used to create the view controller, if it does not yet exist, or return an existing view controller object, if one does exist.
To use a class that adopts this protocol, you must assign that class to the
restorationClass property of one of your app’s view controllers.
Creating the View Controller
Asks the receiver to provide the view controller that corresponds to the specified identifier information. (required)
An array of
NSStringobjects corresponding to the restoration identifiers of the desired view controller and all of its ancestors in the view controller hierarchy. The last value in the array is the restoration identifier of the desired view controller. Earlier entries represent the restoration identifiers of its ancestors.
The keyed archiver containing the app’s saved state information.
The view controller object to use or
nil if you do not want to restore this view controller now.
Your implementation of this method should create (or find) the corresponding view controller object and return it. If your restoration class determines that it does not make sense to display this view controller now, it may return
nil from this method to prevent that view controller (and its children) from being added to your interface during the restoration process.
You use the strings in the identifierComponents parameter to identify the view controller being requested. The view controllers in your app form a hierarchy. At the root of this hierarchy is the window’s root view controller, which itself may present or embed other view controllers. Those presented or embedded view controllers may themselves present and embed other view controllers. The result is a hierarchy of view controller relationships, with each presented or embedded view controller becoming a child of the view controller that presented or embedded it. The strings in the identifierComponents array identify the path through this hierarchy from the root view controller to the desired view controller.
It is not always necessary to create a new view controller object in your implementation of this method. You can also return an existing view controller object that was created by another means. For example, if the view controller had already been loaded from a storyboard file, you would return that object rather than create a new one.
Your implementation of this method may use any data in the provided coder to assist in the restoration process. However, you do not need to restore the entire state of the view controller at this point. During a later pass, view controllers that define a
decodeRestorableStateWithCoder: method are given a chance to restore their state form the same coder object.
- Available in iOS 6.0 and later.
State Restoration Keys
The following keys are used when reading and writing state restoration data.
NSString *const UIStateRestorationViewControllerStoryboardKey;
The value of this key is a
UIStoryboardobject representing the storyboard from which the view controller was initially obtained. Normally, you do not need to write this key to the coder yourself. The
UIViewControllerclass automatically writes this key to the coder during the state preservation process.
Available in iOS 6.0 and later.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)