I have another question about restoring the state of an application on an iPhone. Simple data (such as a selected tab) may be stored in NSUserDefaults, but this is not enough.
I want to restore all the state, including navigation controllers (go to the sub-sub-sub-matrix controller).
My problem is that my application is divided into several xib files, so in the beginning all View controllers are not created. Is there any way to "force" instanciation from an xib file?
(I donโt have the code at hand, but I can try to write a small end if it is not clear)
Many thanks.
[viewController view] XIB ; , .
[viewController view]
:
@class Record; // some model object--I assume it has an integer record ID @class DetailViewController; @interface RootViewController : UIViewController { IBOutlet DetailViewController * detailController; } - (void)restore; ... @end @implementation RootViewController // Note: all detailController showings--even ones from within // RootViewController--should go through this method. - (void)showRecord:(Record*)record animated:(BOOL)animated { [self view]; // ensures detailController is loaded [[NSUserDefaults standardUserDefaults] setInteger:record.recordID forKey:@"record"]; detailController.record = record; [self.navigationController pushViewController:detailController animated:animated]; } - (void)restore { int recordID = [[NSUserDefaults standardUserDefaults] integerForKey:@"record"]; if(recordID) { Record * record = [Record recordWithID:recordID]; [rootViewController showRecord:record animated:NO]; // If DetailViewController has its own state to restore, add this here: // [detailController restore]; } } ... - (void)viewDidAppear:(BOOL)animated { [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"record"]; } @end @implementation MyAppDelegate - (void)applicationDidFinishLaunching:(UIApplication*)application { ... [rootViewController restore]; ... } ... @end
, , .
, Litho Graph. , , . : -viewDidLoad . , ( ). -, ( ).
: . - -initWithNibName: bundle: on super, + alloc -init , .xib . , , :
[self.navigationController pushViewController: controller animated: YES];
, , , , , ; (:
"drilldownsave". ,