From 75ffb17b6e21e9271f65491b6bc8ecc213292a39 Mon Sep 17 00:00:00 2001 From: Sam Soffes Date: Sat, 28 Jul 2012 20:21:26 -0700 Subject: [PATCH] Remember selected list. Fixes #12 --- Cheddar for iOS.xcodeproj/project.pbxproj | 4 ++-- Classes/CDIListsViewController.h | 2 ++ Classes/CDIListsViewController.m | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cheddar for iOS.xcodeproj/project.pbxproj b/Cheddar for iOS.xcodeproj/project.pbxproj index 13571bf..be23ce2 100644 --- a/Cheddar for iOS.xcodeproj/project.pbxproj +++ b/Cheddar for iOS.xcodeproj/project.pbxproj @@ -841,10 +841,10 @@ B23261A215C206EC00D455EF /* Lists */ = { isa = PBXGroup; children = ( - B208BB9C15BF63A80080705D /* CDICreateListViewController.h */, - B208BB9D15BF63A80080705D /* CDICreateListViewController.m */, B208BB9E15BF63A80080705D /* CDIListsViewController.h */, B208BB9F15BF63A80080705D /* CDIListsViewController.m */, + B208BB9C15BF63A80080705D /* CDICreateListViewController.h */, + B208BB9D15BF63A80080705D /* CDICreateListViewController.m */, ); name = Lists; sourceTree = ""; diff --git a/Classes/CDIListsViewController.h b/Classes/CDIListsViewController.h index 99eb1bc..621c568 100644 --- a/Classes/CDIListsViewController.h +++ b/Classes/CDIListsViewController.h @@ -8,6 +8,8 @@ #import "CDIManagedTableViewController.h" +extern NSString *const kCDISelectedListKey; + @interface CDIListsViewController : CDIManagedTableViewController - (void)showSettings:(id)sender; diff --git a/Classes/CDIListsViewController.m b/Classes/CDIListsViewController.m index 7c2e80b..dbed285 100644 --- a/Classes/CDIListsViewController.m +++ b/Classes/CDIListsViewController.m @@ -25,6 +25,8 @@ #import "CDIWebSignInViewController.h" #endif +NSString *const kCDISelectedListKey = @"CDISelectedListKey"; + @interface CDIListsViewController () @property (nonatomic, strong) SMTEDelegateController *textExpander; - (void)_listUpdated:(NSNotification *)notification; @@ -314,6 +316,9 @@ - (void)_selectListAtIndexPath:(NSIndexPath *)indexPath newList:(BOOL)newList { } CDKList *list = [self objectForViewIndexPath:indexPath]; + NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; + [userDefaults setObject:list.remoteID forKey:kCDISelectedListKey]; + [userDefaults synchronize]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { [CDISplitViewController sharedSplitViewController].listViewController.managedObject = list; @@ -494,6 +499,19 @@ - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [super controllerDidChangeContent:controller]; if (_checkForOneList) { + NSNumber *selectedList = [[NSUserDefaults standardUserDefaults] objectForKey:kCDISelectedListKey]; + if (selectedList) { + CDKList *list = [CDKList objectWithRemoteID:selectedList]; + NSIndexPath *fIndexPath = [self.fetchedResultsController indexPathForObject:list]; + if (!fIndexPath) { + _checkForOneList = NO; + return; + } + + NSIndexPath *selectedIndexPath = [self viewIndexPathForFetchedIndexPath:fIndexPath]; + [self _selectListAtIndexPath:selectedIndexPath newList:NO]; + } + if (self.fetchedResultsController.fetchedObjects.count == 1) { [self _selectListAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] newList:NO]; }