uiviewcontroller - iOS State restoration and UINavigationController modal views -


i trying incorporate state restoration in app. have working fine part, presenting navigation controller modal view on top of navigation controller seems challenging.

for testing, created new split-view app on ipad, navigation controllers both sides of split view, , master , detail view controller each side, roots of respective navcontrollers. in master view, can click on button push new testviewcontroller onto navcontroller stack programatically. hook splitview in storyboard, add restorationids everything, opt-in delegate, provide restoration class , adhere uiviewcontrollerrestoration protocol testviewcontroller (since it's created programmatically) , works fine. if close app , retort it, start testviewcontroller pushed onto master's navcontroller. far good.

i change button handler present testviewcontroller inside new uinavigationcontroller, present onto master's navigation controller, show modal view (instead of pushing on nav stack). now, when relaunch app, there no modal view there anymore. testmodalviewcontroller's viewcontrollerwithrestorationidentifierpath:coder: called correctly before, modal view never presented reason.

here code i'm talking about

masterviewcontroller.h:

- (void)pushbutton:(id)sender {     testmodalviewcontroller *test = [[testmodalviewcontroller alloc] initwithnibname:@"testviewcontroller" bundle:nil];     test.restorationidentifier = @"testid";     test.restorationclass = [testmodalviewcontroller class];      uinavigationcontroller *modal = [[uinavigationcontroller alloc] initwithrootviewcontroller:test];     modal.modalpresentationstyle = uimodalpresentationformsheet;     modal.restorationidentifier = @"modaltestid";     [self.navigationcontroller presentviewcontroller:modal animated:yes completion:nil];     return; } 

testmodalviewcontroller.m:

+ (uiviewcontroller *) viewcontrollerwithrestorationidentifierpath:(nsarray *)identifiercomponents coder:(nscoder *)coder {     testmodalviewcontroller *test = [[testmodalviewcontroller alloc] initwithnibname:@"testviewcontroller" bundle:nil];     test.restorationclass = [testmodalviewcontroller class];     test.restorationidentifier = [identifiercomponents lastobject];     return test; } 

perhaps uinavigationcontroller created display modally never preserved? not sure why, because have restorationidentifier.

edit:

after further testing, turns out if remove uinavigationcontroller the pushbutton: code, , present testmodalviewcontroller instance directly, gets restored correctly. uinavigationcontroller being presented uinavigationcontroller?

this works (though not want):

- (void)pushbutton:(id)sender {     testmodalviewcontroller *test = [[testmodalviewcontroller alloc] initwithnibname:@"testviewcontroller" bundle:nil];     test.restorationidentifier = @"testid";     test.restorationclass = [testmodalviewcontroller class];      //uinavigationcontroller *modal = [[uinavigationcontroller alloc] initwithrootviewcontroller:test];     //modal.modalpresentationstyle = uimodalpresentationformsheet;     //modal.restorationidentifier = @"modaltestid";     [self.navigationcontroller presentviewcontroller:test animated:yes completion:nil];     return; } 

edit: attached link test project: dropbox.com/sh/w8herpy2djjl1kw/vw_zwqimgt

it's core data master-detail template; run on ipad simulator. + button in master invokes testmodalvc; if press home button, kill debugger , launch again, see snapshot contains testmodalvc when app launched, doesn't restored

you can either create own restoration class handle this, or add following app delegate:

- (uiviewcontroller *)application:(uiapplication *)application viewcontrollerwithrestorationidentifierpath:(nsarray *)identifiercomponents coder:(nscoder *)coder {     nsstring *lastidentifier = [identifiercomponents lastobject];     if ([lastidentifier isequaltostring:@"modaltestid"])     {         uinavigationcontroller *nc = [[uinavigationcontroller alloc] init];         nc.restorationidentifier = @"modaltestid";         return nc;     }     else if(...) //other navigation controllers     {     }      return nil; } 

more information in documentation.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -