diff options
author | matt handler <matt.handler@gmail.com> | 2011-04-27 18:45:32 -0400 |
---|---|---|
committer | matt handler <matt.handler@gmail.com> | 2011-04-27 18:45:32 -0400 |
commit | e788dbb246a2c9673d595420beca061123526d50 (patch) | |
tree | 70fbbee15ffdaef04c6b7afee40c2964e41fbcac /Classes/SectionDictionary.m | |
parent | e6eb634beac831e64becc03928a467701f9625cf (diff) | |
download | piccast-app-e788dbb246a2c9673d595420beca061123526d50.tar.gz piccast-app-e788dbb246a2c9673d595420beca061123526d50.zip |
sorting automatically, load more button, remove some logging, customizing things?
Diffstat (limited to 'Classes/SectionDictionary.m')
-rw-r--r-- | Classes/SectionDictionary.m | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/Classes/SectionDictionary.m b/Classes/SectionDictionary.m index b183725..9124714 100644 --- a/Classes/SectionDictionary.m +++ b/Classes/SectionDictionary.m @@ -15,6 +15,7 @@ - (SectionDictionary *) init { index = 0; + sortedKeys = [[[NSMutableArray alloc] init] retain]; indexMap = [[[NSMutableDictionary alloc] init] retain]; theRealDictionary = [[[NSMutableDictionary alloc] init] retain]; [super init]; @@ -27,22 +28,39 @@ return theRealDictionary; } +- (void) sortKeys { + [sortedKeys sortUsingComparator:(NSComparator)^(id obj1, id obj2){ + return [obj2 compare:obj1]; + }]; +} + - (void) setObject:(id)anObject forKey:(id)aKey { - [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]]; - index++; +// [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]]; +// index++; [theRealDictionary setObject:anObject forKey:aKey]; + + [sortedKeys addObject:aKey]; + [self sortKeys]; +} + +- (NSArray *) allIndices { + NSLog(@"%@ %@", [indexMap allKeys], [indexMap allValues]); + return [indexMap allKeys]; } // lets you push objects into sections without worry about storage - (void) appendObject:(id)anObject forKey:(id)aKey { NSMutableArray *store = [theRealDictionary objectForKey:aKey]; if (store == nil) { - [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]]; - index++; +// [indexMap setObject:aKey forKey:[NSString stringWithFormat:@"%d", index]]; +// index++; NSMutableArray *store = [[[NSMutableArray alloc] init] autorelease]; [store addObject:anObject]; [theRealDictionary setObject:store forKey:aKey]; + + [sortedKeys addObject:aKey]; + [self sortKeys]; } else [store addObject:anObject]; @@ -50,14 +68,17 @@ } - (id) objectForIndex:(NSInteger)i { - return [theRealDictionary objectForKey:[indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]]; + return [theRealDictionary objectForKey:[sortedKeys objectAtIndex:i]]; + //return [theRealDictionary objectForKey:[indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]]; } - (NSString *) keyForIndex:(NSInteger)i { - return [indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]; + return [sortedKeys objectAtIndex:i]; + //return [indexMap objectForKey:[NSString stringWithFormat:@"%d", i]]; } - (void) dealloc { + [sortedKeys release]; [theRealDictionary release]; [indexMap release]; [super dealloc]; |