ios - iOS 中使用 MMDrawer 的状态保存和恢复问题

标签 ios objective-c state-restoration mmdrawercontroller

我已经在 iOS 应用程序中集成了 MMDrawerController 库,现在我需要恢复应用程序状态,即使应用程序在后台被杀死(仅当应用程序进入从前景到背景),它在正常的导航应用程序中工作正常,但是当我在我的应用程序中使用“setCenterViewController”选项更改导航时,恢复没有按预期工作,我已经按照此中提供的所有说明进行操作链接:“https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html

我使用了 setCenterViewController 选项(从 MMDrawer 推荐)导航到特定屏幕,然后在后台删除了应用程序,当我们重新打开它时,它以默认初始屏幕启动,但我们期望它应该重新打开进入后台之前的屏幕。

这是代码片段:

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
appDelegate.homeController.navigationController.navigationBarHidden = YES;
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UINavigationController *_navg = [[UINavigationController alloc]initWithRootViewController:homeVC];
_navg.restorationIdentifier = @"homeNavigationController";
homeVC.title = [self.dataSource objectAtIndex:indexPath.row]; homeVC.restorationIdentifier = @"HomeViewController";
[appDelegate.drawerController setCenterViewController:_navg withCloseAnimation:YES completion:nil];
self.currentViewController = _navg;
self.currentViewController.restorationIdentifier = @"homeNavigationController"; 

帮我解决这个问题。

最佳答案

您可以通过将状态存储在 NSUUserDefault 中轻松地进行状态保存 执行以下步骤: 1.首次启动应用程序时。

  {
      UserDefaults.standard.set("0", forKey: "state")
     UserDefaults.standard.synchronize()
   }

2.当你杀死应用程序然后存储状态

   {    
            UserDefaults.standard.set("1", forKey: "state")
             UserDefaults.standard.synchronize()
        }

3. When you relaunch the app get the state ,setup the drawer and move to particular controller using it's navigation controller.



 if let state = UserDefaults.standard.object(forKey: "state") as? String{
         switch state{
                case "0":
                        //Do setup for MMDrawer for center ,left and right view
                        break
                case "1":
                        //Do setup for MMDrawer for center ,left and right view

                break
                 default:
                        break
                    }
                }

关于ios - iOS 中使用 MMDrawer 的状态保存和恢复问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38008895/

相关文章:

ios - 添加Firebase SDK后未调用didRegisterForRemoteNotificationsWithDeviceToken。禁用漩涡

ios - iOS 中的状态恢复

ios - 状态恢复发出警告 - 导致莫名其妙的视觉偏差

ios - 状态恢复期间的 UIAppearance 错误

iOS - 如何从核心数据实体创建 View

ios - 不同 iOS iPhone 尺寸的全屏图像

ios - NSLog 与某些 NSURL 崩溃 - iOS 9.2

ios - 将应用上传到应用商店后的状态 “Missing Screenshot [1]”

ios - "Format string is not string literal (potentially insecure)"

objective-c - NSWindow 之上的 iTunes 组件