keep view controller self-contained for state save/restore

This commit is contained in:
Justin R. Miller
2014-05-13 11:01:32 -07:00
parent 7bfcde4025
commit 6668b9b303
2 changed files with 16 additions and 12 deletions

View File

@@ -21,15 +21,4 @@
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[(MBXViewController *)self.window.rootViewController saveState];
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[(MBXViewController *)self.window.rootViewController restoreState];
}
@end
@end

View File

@@ -36,6 +36,19 @@ MBXViewController *viewController = nullptr;
#pragma mark - Setup
- (id)init
{
self = [super init];
if (self)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveState) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(restoreState) name:UIApplicationWillEnterForegroundNotification object:nil];
}
return self;
}
- (void)loadView
{
[super loadView];
@@ -252,6 +265,8 @@ MBXViewController *viewController = nullptr;
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (settings)
{
// Save settings