mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-21 10:54:31 +08:00
API cleanup work in progress on Table Controller
This commit is contained in:
@@ -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<RKTableControllerDelegate> 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;
|
||||
|
||||
@@ -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 @@ static NSString* lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey";
|
||||
|
||||
#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 @@ static NSString* lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey";
|
||||
}
|
||||
}
|
||||
|
||||
- (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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -324,6 +324,7 @@
|
||||
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.)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -245,6 +245,19 @@
|
||||
[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 {
|
||||
|
||||
Reference in New Issue
Block a user