Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is RestorationIdentifier?

I am wondering what RestorationIdentifier is, and why would we use it? I saw RestorationIdentifier on MMDrawerController. MMDrawerController using like this : `

[self setRestorationIdentifier:@"MMExampleCenterControllerRestorationKey"];`
like image 449
Erhan Demirci Avatar asked Nov 25 '13 15:11

Erhan Demirci


2 Answers

Consider that you want to allow your user to close the app and then return to exactly where they were when they open the app again. And you should want to do that. Broadly you have 2 options:

  1. Implement it yourself, saving everything into user defaults or similar and reconstructing the view hierarchy yourself
  2. Use Apple State Preservation which will automatically rebuild the view hierarchy for you and which you can tie into to save and restore other pertinent information

Option 2 is behind the use of the restoration id (so that the view hierarchy can be recorded and rebuilt).

like image 122
Wain Avatar answered Oct 04 '22 02:10

Wain


It is a property of UIViewController which indicates whether the ViewController and its contents should be preserved and is also used to identify the ViewController during the restoration/relaunch process.

Ref : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instp/UIViewController/restorationIdentifier

like image 20
ioopl Avatar answered Oct 04 '22 04:10

ioopl