iphone - iOS state restoration issue with DrawerController -
i have app written in swift 3.1, using xcode 8.3.3.
i trying implement state preservation/restoration.
to have implemented shouldsaveapplicationstate
, willfinishlaunchingwithoptions
methods in appdelegate.swift
, set return true
:
// appdelegate.swift // state restoration callbacks func application(_ application: uiapplication, shouldsaveapplicationstate coder: nscoder) -> bool { debug_print(this: "shouldsaveapplicationstate") return true } func application(_ application: uiapplication, shouldrestoreapplicationstate coder: nscoder) -> bool { debug_print(this: "shouldrestoreapplicationstate") restoringstate = true return true } func application(application: uiapplication, willfinishlaunchingwithoptions launchoptions: [nsobject : anyobject]?) -> bool { debug_print(this: "willfinishlaunchingwithoptions") return true }
i’ve provided restoration ids involved viewcontrollers , navigationcontrollers.
i'm using 3rd party library handle side drawer navigation container (https://github.com/sascha/drawercontroller). initial viewcontroller set programmatically inside didfinishlaunchingwithoptions method, see below.
// appdelegate.swift var centercontainer: drawercontroller? func application(_ application: uiapplication, didfinishlaunchingwithoptions launchoptions: [uiapplicationlaunchoptionskey: any]?) -> bool { let mainstoryboard: uistoryboard = uistoryboard(name: "main", bundle: nil) let centerviewcontroller = mainstoryboard.instantiateviewcontroller(withidentifier: "rootviewcontrollernav") as! uinavigationcontroller let leftviewcontroller = mainstoryboard.instantiateviewcontroller(withidentifier: "sidedrawerviewcontroller") as! uitableviewcontroller centercontainer = drawercontroller(centerviewcontroller: centerviewcontroller, leftdrawerviewcontroller: leftviewcontroller) centercontainer?.restorationidentifier = "drawercontrollerview" window = uiwindow(frame: uiscreen.main.bounds) window?.restorationidentifier = "mainwindow" window?.rootviewcontroller = centercontainer window?.makekeyandvisible() return true }
when app opens , attempts restore state, displays correct viewcontroller (last controller before app closed) temporarily, once app becomes active reverts initial viewcontroller.
for example, following happens:
- open app navigate “settings” view via side menu
- navigate home screen
- stop running xcode , start again
- app open showing settings view, revert home view
can tell me causing this, or going wrong? let me know if need more code examples.
func application(_ application: uiapplication, didfinishlaunchingwithoptions launchoptions: [uiapplicationlaunchoptionskey: any]?) -> bool { // override point customization after application launch. let mainstoryboard: uistoryboard = uistoryboard(name: "main", bundle: nil) let leftsidedrawerviewcontroller = mainstoryboard.instantiateviewcontroller(withidentifier: "sidedrawerviewcontroller") as! uitableviewcontroller let centerviewcontroller = mainstoryboard.instantiateviewcontroller(withidentifier: "rootviewcontrollernav") as! uinavigationcontroller let navigationcontroller = uinavigationcontroller(rootviewcontroller: centerviewcontroller) navigationcontroller.restorationidentifier = "navigationcontrollerkey" let leftsidenavcontroller = uinavigationcontroller(rootviewcontroller: leftsidedrawerviewcontroller) leftsidenavcontroller.restorationidentifier = "leftnavigationcontroller" self.drawercontroller = drawercontroller(centerviewcontroller: navigationcontroller, leftdrawerviewcontroller: leftsidenavcontroller, rightdrawerviewcontroller: nil) self.drawercontroller.opendrawergesturemodemask = .all self.drawercontroller.closedrawergesturemodemask = .all self.window = uiwindow(frame: uiscreen.main.bounds) self.window?.rootviewcontroller = self.drawercontroller return true }
Comments
Post a Comment