重点应该是最后一个方法,那样写UITabBarViewController的恢复请问有没有什么问题,因为模拟器的结果是tabViewController 的子视图控制器是不能恢复的
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
return YES;
}
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if(!self.window.rootViewController) {BNRHypnosisViewController *hvc = [[BNRHypnosisViewController alloc] init]; NSBundle *appBundle = [NSBundle mainBundle]; BNRReminderViewController *rvc = [[BNRReminderViewController alloc] initWithNibName: @"BNRReminderViewController" bundle: appBundle]; UITabBarController *tabBarController = [UITabBarController new]; tabBarController.viewControllers = @[hvc, rvc]; tabBarController.tabBar.tintColor = [UIColor redColor]; //设置恢复标识 tabBarController.restorationIdentifier = NSStringFromClass([tabBarController class]); self.window.rootViewController = tabBarController;
}
[self.window makeKeyAndVisible];
/*[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];*/
// [application registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories: nil]];
return YES;
}
//恢复类
-(UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
UIViewController *tabBarController = [[UITabBarController alloc] init];tabBarController.restorationIdentifier = NSStringFromClass([tabBarController class]);
//背景颜色红色,方便调试
tabBarController.view.backgroundColor = [UIColor redColor];self.window.rootViewController = tabBarController;
return tabBarController;
}