Problem restoring iOS state using DrawerController

I have an application written in Swift 3.1 using Xcode 8.3.3.

I'm currently trying to implement state save / restore.

For this I used the methods shouldSaveApplicationStateand willFinishLaunchingWithOptionsin AppDelegate.swiftand set the return statement 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
}

Ive also provided recovery identifiers for all involved view controllers and navigation controllers.

I use a third-party library to handle the side-box navigation container ( https://github.com/sascha/DrawerController ). The initial view manager is set programmatically inside the 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
}

, ( ), , , .

, :

  • ""
  • xcode
  • ,

- , , ? , .

+4
1
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for 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
    }     
0

Source: https://habr.com/ru/post/1685497/


All Articles