Skip to content

Commit

Permalink
API cleanup work in progress on Table Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Feb 24, 2012
1 parent 2040283 commit c0ae954
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
11 changes: 1 addition & 10 deletions Code/UI/RKAbstractTableController.h
Expand Up @@ -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;

Expand Down Expand Up @@ -75,7 +68,7 @@ extern NSString* const RKTableControllerDidBecomeOffline;
}

/////////////////////////////////////////////////////////////////////////
/// @name Basic Configuration
/// @name Configuring the Table Controller
/////////////////////////////////////////////////////////////////////////

@property (nonatomic, assign) id<RKTableControllerDelegate> delegate;
Expand Down Expand Up @@ -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;
Expand Down
45 changes: 18 additions & 27 deletions Code/UI/RKAbstractTableController.m
Expand Up @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion Code/UI/RKFetchedResultsTableController.h
Expand Up @@ -22,7 +22,6 @@

typedef UIView*(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteger sectionIndex, NSString* sectionTitle);

// TODO: Conditionally compile me based on Core Data?
@interface RKFetchedResultsTableController : RKAbstractTableController <NSFetchedResultsControllerDelegate> {
@private
NSFetchedResultsController* _fetchedResultsController;
Expand Down
1 change: 1 addition & 0 deletions Code/UI/RKFetchedResultsTableController.m
Expand Up @@ -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.)
Expand Down
9 changes: 7 additions & 2 deletions Code/UI/RKTableController.h
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions Code/UI/RKTableController.m
Expand Up @@ -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 {
Expand Down

0 comments on commit c0ae954

Please sign in to comment.