From c0ae954fb915e41ff02b5cc8b9bf8b82bea4a377 Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Thu, 23 Feb 2012 23:25:31 -0500 Subject: [PATCH] API cleanup work in progress on Table Controller --- Code/UI/RKAbstractTableController.h | 11 +----- Code/UI/RKAbstractTableController.m | 45 +++++++++-------------- Code/UI/RKFetchedResultsTableController.h | 1 - Code/UI/RKFetchedResultsTableController.m | 1 + Code/UI/RKTableController.h | 9 ++++- Code/UI/RKTableController.m | 13 +++++++ 6 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Code/UI/RKAbstractTableController.h b/Code/UI/RKAbstractTableController.h index 4a7f19aa66..98029279cb 100755 --- a/Code/UI/RKAbstractTableController.h +++ b/Code/UI/RKAbstractTableController.h @@ -30,13 +30,6 @@ /** @name Constants */ -/** - A tag used to identify the overlay view used to draw the loading, error, - and empty views over the table view. - */ -// TODO: Maybe this just becomes a UIImageView ivar... -// extern const NSUInteger RKTableControllerOverlayViewTag; - /** Posted when the table view model starts loading */ extern NSString* const RKTableControllerDidStartLoadNotification; @@ -75,7 +68,7 @@ extern NSString* const RKTableControllerDidBecomeOffline; } ///////////////////////////////////////////////////////////////////////// -/// @name Basic Configuration +/// @name Configuring the Table Controller ///////////////////////////////////////////////////////////////////////// @property (nonatomic, assign) id delegate; @@ -146,8 +139,6 @@ extern NSString* const RKTableControllerDidBecomeOffline; @property (nonatomic, assign) BOOL autoRefreshFromNetwork; @property (nonatomic, assign) NSTimeInterval autoRefreshRate; -- (void)loadTableFromResourcePath:(NSString *)resourcePath; -- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *objectLoader))block; - (void)loadTableWithObjectLoader:(RKObjectLoader *)objectLoader; - (void)cancelLoad; - (BOOL)isAutoRefreshNeeded; diff --git a/Code/UI/RKAbstractTableController.m b/Code/UI/RKAbstractTableController.m index 14b26c9115..7770fa0c0f 100755 --- a/Code/UI/RKAbstractTableController.m +++ b/Code/UI/RKAbstractTableController.m @@ -36,7 +36,6 @@ */ #define BOUNCE_PIXELS 5.0 -//const NSUInteger RKTableControllerOverlayViewTag = 123456789; NSString* const RKTableControllerDidStartLoadNotification = @"RKTableControllerDidStartLoadNotification"; NSString* const RKTableControllerDidFinishLoadNotification = @"RKTableControllerDidFinishLoadNotification"; NSString* const RKTableControllerDidLoadObjectsNotification = @"RKTableControllerDidLoadObjectsNotification"; @@ -643,42 +642,20 @@ - (NSIndexPath *)tableView:(UITableView*)theTableView willSelectRowAtIndexPath:( #pragma mark - Network Table Loading -- (void)loadTableFromResourcePath:(NSString*)resourcePath { - NSAssert(self.objectManager, @"Cannot perform a network load without an object manager"); - [self loadTableWithObjectLoader:[self.objectManager loaderWithResourcePath:resourcePath]]; -} - -- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *loader))block { - RKObjectLoader* theObjectLoader = [self.objectManager loaderWithResourcePath:resourcePath]; - block(theObjectLoader); - [self loadTableWithObjectLoader:theObjectLoader]; -} - -- (void)loadTableWithObjectLoader:(RKObjectLoader*)theObjectLoader { - NSAssert(theObjectLoader, @"Cannot perform a network load without an object loader"); - if (! [self.objectLoader isEqual:theObjectLoader]) { - theObjectLoader.delegate = self; - self.objectLoader = theObjectLoader; - } - if ([self.delegate respondsToSelector:@selector(tableController:willLoadTableWithObjectLoader:)]) { - [self.delegate tableController:self willLoadTableWithObjectLoader:self.objectLoader]; - } - if (self.objectLoader.queue && ![self.objectLoader.queue containsRequest:self.objectLoader]) { - [self.objectLoader.queue addRequest:self.objectLoader]; - } -} - - (void)cancelLoad { [self.objectLoader cancel]; } - (NSDate*)lastUpdatedDate { + if (! self.objectLoader) { + return nil; + } + if (_autoRefreshFromNetwork) { NSAssert(_cache, @"Found a nil cache when trying to read our last loaded time"); NSDictionary* lastUpdatedDates = [_cache dictionaryForCacheKey:lastUpdatedDateDictionaryKey]; RKLogTrace(@"Last updated dates dictionary retrieved from tableController cache: %@", lastUpdatedDates); if (lastUpdatedDates) { - NSAssert(self.objectLoader, @"Found a nil objectLoader when attempting to retrieve our last loaded time"); NSString* absoluteURLString = [self.objectLoader.URL absoluteString]; NSNumber* lastUpdatedTimeIntervalSince1970 = (NSNumber*)[lastUpdatedDates objectForKey:absoluteURLString]; if (absoluteURLString && lastUpdatedTimeIntervalSince1970) { @@ -1368,4 +1345,18 @@ - (void)resizeTableViewForKeyboard:(NSNotification*)notification { } } +- (void)loadTableWithObjectLoader:(RKObjectLoader*)theObjectLoader { + NSAssert(theObjectLoader, @"Cannot perform a network load without an object loader"); + if (! [self.objectLoader isEqual:theObjectLoader]) { + theObjectLoader.delegate = self; + self.objectLoader = theObjectLoader; + } + if ([self.delegate respondsToSelector:@selector(tableController:willLoadTableWithObjectLoader:)]) { + [self.delegate tableController:self willLoadTableWithObjectLoader:self.objectLoader]; + } + if (self.objectLoader.queue && ![self.objectLoader.queue containsRequest:self.objectLoader]) { + [self.objectLoader.queue addRequest:self.objectLoader]; + } +} + @end diff --git a/Code/UI/RKFetchedResultsTableController.h b/Code/UI/RKFetchedResultsTableController.h index e66dcdce7b..f0123afb3b 100755 --- a/Code/UI/RKFetchedResultsTableController.h +++ b/Code/UI/RKFetchedResultsTableController.h @@ -22,7 +22,6 @@ typedef UIView*(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteger sectionIndex, NSString* sectionTitle); -// TODO: Conditionally compile me based on Core Data? @interface RKFetchedResultsTableController : RKAbstractTableController { @private NSFetchedResultsController* _fetchedResultsController; diff --git a/Code/UI/RKFetchedResultsTableController.m b/Code/UI/RKFetchedResultsTableController.m index 955b6e9e48..5a7c78efcb 100755 --- a/Code/UI/RKFetchedResultsTableController.m +++ b/Code/UI/RKFetchedResultsTableController.m @@ -324,6 +324,7 @@ - (UITableViewCell *)cellForObjectAtIndexPath:(NSIndexPath *)indexPath { NSError* error = nil; BOOL success = [mappingOperation performMapping:&error]; [mappingOperation release]; + // NOTE: If there is no mapping work performed, but no error is generated then // we consider the operation a success. It is common for table cells to not contain // any dynamically mappable content (i.e. header/footer rows, banners, etc.) diff --git a/Code/UI/RKTableController.h b/Code/UI/RKTableController.h index 0600f6ca58..184b08c068 100644 --- a/Code/UI/RKTableController.h +++ b/Code/UI/RKTableController.h @@ -48,7 +48,7 @@ After the block is invoked, the objects will be loaded into the specified section. */ // TODO: Update comments... -- (void)loadTableItems:(NSArray *)tableItems withMappingBlock:(void (^)(RKTableViewCellMapping *))block; +- (void)loadTableItems:(NSArray *)tableItems withMappingBlock:(void (^)(RKTableViewCellMapping *))block; // TODO: Eliminate... - (void)loadTableItems:(NSArray *)tableItems withMapping:(RKTableViewCellMapping *)cellMapping; - (void)loadTableItems:(NSArray *)tableItems inSection:(NSUInteger)sectionIndex @@ -79,12 +79,17 @@ */ - (void)loadTableItems:(NSArray *)tableItems inSection:(NSUInteger)sectionIndex; +/** @name Network Tables */ + +- (void)loadTableFromResourcePath:(NSString *)resourcePath; +- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *objectLoader))block; + /** @name Forms */ /** The form that the table has been loaded with (if any) */ -@property (nonatomic, retain) RKForm *form; +@property (nonatomic, retain, readonly) RKForm *form; /** Loads the table with the contents of the specified form object. diff --git a/Code/UI/RKTableController.m b/Code/UI/RKTableController.m index f9e89a0d5e..2618cd270b 100644 --- a/Code/UI/RKTableController.m +++ b/Code/UI/RKTableController.m @@ -245,6 +245,19 @@ - (void)loadTableItems:(NSArray *)tableItems withMappingBlock:(void (^)(RKTableV [self loadTableItems:tableItems inSection:0 withMapping:[RKTableViewCellMapping cellMappingUsingBlock:block]]; } +#pragma mark - Network Table Loading + +- (void)loadTableFromResourcePath:(NSString*)resourcePath { + NSAssert(self.objectManager, @"Cannot perform a network load without an object manager"); + [self loadTableWithObjectLoader:[self.objectManager loaderWithResourcePath:resourcePath]]; +} + +- (void)loadTableFromResourcePath:(NSString *)resourcePath usingBlock:(void (^)(RKObjectLoader *loader))block { + RKObjectLoader* theObjectLoader = [self.objectManager loaderWithResourcePath:resourcePath]; + block(theObjectLoader); + [self loadTableWithObjectLoader:theObjectLoader]; +} + #pragma mark - Forms - (void)loadForm:(RKForm *)form {