Skip to content

Commit

Permalink
Remember selected list. Fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Jul 29, 2012
1 parent cc0c403 commit 75ffb17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cheddar for iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>";
Expand Down
2 changes: 2 additions & 0 deletions Classes/CDIListsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "CDIManagedTableViewController.h"

extern NSString *const kCDISelectedListKey;

@interface CDIListsViewController : CDIManagedTableViewController

- (void)showSettings:(id)sender;
Expand Down
18 changes: 18 additions & 0 deletions Classes/CDIListsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#import "CDIWebSignInViewController.h"
#endif

NSString *const kCDISelectedListKey = @"CDISelectedListKey";

@interface CDIListsViewController ()
@property (nonatomic, strong) SMTEDelegateController *textExpander;
- (void)_listUpdated:(NSNotification *)notification;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit 75ffb17

Please sign in to comment.