mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Cleanups to and test coverage expansion of RKTableController API's. refs #765
This commit is contained in:
31
Code/Testing/RKTableControllerTestDelegate.h
Normal file
31
Code/Testing/RKTableControllerTestDelegate.h
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// RKTableControllerTestDelegate.h
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 5/23/12.
|
||||
// Copyright (c) 2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import "RKTableController.h"
|
||||
#import "RKFetchedResultsTableController.h"
|
||||
|
||||
@interface RKAbstractTableControllerTestDelegate : NSObject <RKAbstractTableControllerDelegate>
|
||||
|
||||
@property(nonatomic, readonly, getter = isCancelled) BOOL cancelled;
|
||||
@property(nonatomic, assign) NSTimeInterval timeout;
|
||||
@property(nonatomic, assign) BOOL awaitingResponse;
|
||||
|
||||
+ (id)tableControllerDelegate;
|
||||
- (void)waitForLoad;
|
||||
|
||||
@end
|
||||
|
||||
@interface RKTableControllerTestDelegate : RKAbstractTableControllerTestDelegate <RKTableControllerDelegate>
|
||||
@end
|
||||
|
||||
@interface RKFetchedResultsTableControllerTestDelegate : RKAbstractTableControllerTestDelegate <RKFetchedResultsTableControllerDelegate>
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
139
Code/Testing/RKTableControllerTestDelegate.m
Normal file
139
Code/Testing/RKTableControllerTestDelegate.m
Normal file
@@ -0,0 +1,139 @@
|
||||
//
|
||||
// RKTableControllerTestDelegate.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 5/23/12.
|
||||
// Copyright (c) 2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKTableControllerTestDelegate.h"
|
||||
#import "RKLog.h"
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
@implementation RKAbstractTableControllerTestDelegate
|
||||
|
||||
@synthesize timeout = _timeout;
|
||||
@synthesize awaitingResponse = _awaitingResponse;
|
||||
@synthesize cancelled = _cancelled;
|
||||
|
||||
+ (id)tableControllerDelegate {
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_timeout = 1.0;
|
||||
_awaitingResponse = NO;
|
||||
_cancelled = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)waitForLoad {
|
||||
_awaitingResponse = YES;
|
||||
NSDate *startDate = [NSDate date];
|
||||
|
||||
while (_awaitingResponse) {
|
||||
RKLogTrace(@"Awaiting response = %d", _awaitingResponse);
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
|
||||
if ([[NSDate date] timeIntervalSinceDate:startDate] > self.timeout) {
|
||||
NSLog(@"%@: Timed out!!!", self);
|
||||
_awaitingResponse = NO;
|
||||
[NSException raise:nil format:@"*** Operation timed out after %f seconds...", self.timeout];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma RKTableControllerDelegate methods
|
||||
|
||||
- (void)tableControllerDidFinishLoad:(RKAbstractTableController *)tableController {
|
||||
_awaitingResponse = NO;
|
||||
}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didFailLoadWithError:(NSError *)error {
|
||||
_awaitingResponse = NO;
|
||||
}
|
||||
|
||||
- (void)tableControllerDidCancelLoad:(RKAbstractTableController *)tableController {
|
||||
_awaitingResponse = NO;
|
||||
_cancelled = YES;
|
||||
}
|
||||
|
||||
- (void)tableControllerDidFinalizeLoad:(RKAbstractTableController *)tableController {
|
||||
_awaitingResponse = NO;
|
||||
}
|
||||
|
||||
// NOTE - Delegate methods below are implemented to allow trampoline through
|
||||
// OCMock expectations
|
||||
|
||||
- (void)tableControllerDidStartLoad:(RKAbstractTableController *)tableController
|
||||
{}
|
||||
|
||||
- (void)tableControllerDidBecomeEmpty:(RKAbstractTableController *)tableController
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController *)tableController willLoadTableWithObjectLoader:(RKObjectLoader *)objectLoader
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didLoadTableWithObjectLoader:(RKObjectLoader *)objectLoader
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController willBeginEditing:(id)object atIndexPath:(NSIndexPath*)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didEndEditing:(id)object atIndexPath:(NSIndexPath*)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didInsertSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didRemoveSection:(RKTableSection*)section atIndex:(NSUInteger)sectionIndex
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didInsertObject:(id)object atIndexPath:(NSIndexPath*)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didUpdateObject:(id)object atIndexPath:(NSIndexPath*)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController didDeleteObject:(id)object atIndexPath:(NSIndexPath*)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController willAddSwipeView:(UIView*)swipeView toCell:(UITableViewCell*)cell forObject:(id)object
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController*)tableController willRemoveSwipeView:(UIView*)swipeView fromCell:(UITableViewCell*)cell forObject:(id)object
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController *)tableController willDisplayCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didSelectCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath
|
||||
{}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKTableControllerTestDelegate
|
||||
|
||||
- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(RKTableSection *)section
|
||||
{}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKFetchedResultsTableControllerTestDelegate
|
||||
|
||||
- (void)tableController:(RKFetchedResultsTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex
|
||||
{}
|
||||
|
||||
- (void)tableController:(RKFetchedResultsTableController *)tableController didDeleteSectionAtIndex:(NSUInteger)sectionIndex
|
||||
{}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -152,6 +152,7 @@ typedef NSUInteger RKTableControllerState;
|
||||
*/
|
||||
- (NSIndexPath *)indexPathForObject:(id)object;
|
||||
- (UITableViewCell *)cellForObject:(id)object;
|
||||
- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Header and Footer Rows
|
||||
@@ -399,7 +400,6 @@ typedef NSUInteger RKTableControllerState;
|
||||
- (void)tableControllerDidFinishLoad:(RKAbstractTableController *)tableController;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didFailLoadWithError:(NSError *)error;
|
||||
- (void)tableControllerDidCancelLoad:(RKAbstractTableController *)tableController;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex; // NOT IMPLEMENTED
|
||||
|
||||
/**
|
||||
Sent to the delegate when the controller is really and truly finished loading/updating, whether from the network or from Core Data,
|
||||
@@ -422,11 +422,6 @@ typedef NSUInteger RKTableControllerState;
|
||||
*/
|
||||
- (void)tableControllerDidBecomeOffline:(RKAbstractTableController *)tableController;
|
||||
|
||||
// Sections
|
||||
// TODO: Can these even be implemented???
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didRemoveSectionAtIndex:(NSUInteger)sectionIndex;
|
||||
|
||||
// Objects
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didInsertObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didUpdateObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
|
||||
@@ -440,16 +435,10 @@ typedef NSUInteger RKTableControllerState;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController willAddSwipeView:(UIView *)swipeView toCell:(UITableViewCell *)cell forObject:(id)object;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController willRemoveSwipeView:(UIView *)swipeView fromCell:(UITableViewCell *)cell forObject:(id)object;
|
||||
|
||||
// BELOW NOT YET IMPLEMENTED
|
||||
|
||||
// Cells
|
||||
- (void)tableController:(RKAbstractTableController *)tableController willDisplayCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didSelectCell:(UITableViewCell *)cell forObject:(id)object atIndexPath:(NSIndexPath *)indexPath;
|
||||
|
||||
// Objects
|
||||
- (void)tableControllerDidBeginUpdates:(RKAbstractTableController *)tableController;
|
||||
- (void)tableControllerDidEndUpdates:(RKAbstractTableController *)tableController;
|
||||
|
||||
@end
|
||||
|
||||
#endif // TARGET_OS_IPHONE
|
||||
|
||||
@@ -112,7 +112,7 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
self = [self init];
|
||||
if (self) {
|
||||
self.tableView = theTableView;
|
||||
self.viewController = theViewController;
|
||||
_viewController = theViewController; // Assign directly to avoid side-effect of overloaded accessor method
|
||||
self.variableHeightRows = NO;
|
||||
self.defaultRowAnimation = UITableViewRowAnimationFade;
|
||||
self.overlayFrame = CGRectZero;
|
||||
@@ -201,8 +201,6 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
}
|
||||
|
||||
- (void)setViewController:(UIViewController *)viewController {
|
||||
_viewController = viewController;
|
||||
|
||||
if ([viewController isKindOfClass:[UITableViewController class]]) {
|
||||
self.tableView = [(UITableViewController*)viewController tableView];
|
||||
}
|
||||
@@ -466,6 +464,10 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
RKLogTrace(@"%@: Invoking onSelectCellForObjectAtIndexPath block with cellMapping %@ for object %@ at indexPath = %@", self, cell, object, indexPath);
|
||||
cellMapping.onSelectCellForObjectAtIndexPath(cell, object, indexPath);
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didSelectCell:forObject:atIndexPath:)]) {
|
||||
[self.delegate tableController:self didSelectCell:cell forObject:object atIndexPath:indexPath];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)theTableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
@@ -476,6 +478,10 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
if (cellMapping.onCellWillAppearForObjectAtIndexPath) {
|
||||
cellMapping.onCellWillAppearForObjectAtIndexPath(cell, mappableObject, indexPath);
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:willDisplayCell:forObject:atIndexPath:)]) {
|
||||
[self.delegate tableController:self willDisplayCell:cell forObject:mappableObject atIndexPath:indexPath];
|
||||
}
|
||||
|
||||
// Informal protocol
|
||||
// TODO: Needs documentation!!!
|
||||
@@ -633,7 +639,7 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
|
||||
- (void)requestDidStartLoad:(RKRequest *)request {
|
||||
RKLogTrace(@"tableController %@ started loading.", self);
|
||||
self.loading = YES;
|
||||
[self didStartLoad];
|
||||
}
|
||||
|
||||
- (void)requestDidCancelLoad:(RKRequest *)request {
|
||||
@@ -673,8 +679,7 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
|
||||
- (void)objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error {
|
||||
RKLogError(@"tableController %@ failed network load with error: %@", self, error);
|
||||
self.error = error;
|
||||
[self didFinishLoad];
|
||||
[self didFailLoadWithError:error];
|
||||
}
|
||||
|
||||
- (void)objectLoaderDidFinishLoading:(RKObjectLoader *)objectLoader {
|
||||
@@ -686,13 +691,26 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
[self didFinishLoad];
|
||||
}
|
||||
|
||||
- (void)didStartLoad {
|
||||
self.loading = YES;
|
||||
}
|
||||
|
||||
- (void)didFailLoadWithError:(NSError *)error {
|
||||
self.error = error;
|
||||
[self didFinishLoad];
|
||||
}
|
||||
|
||||
- (void)didFinishLoad {
|
||||
self.empty = [self isConsideredEmpty];
|
||||
self.loading = [self.objectLoader isLoading]; // Mutate loading state after we have adjusted empty
|
||||
self.loaded = YES;
|
||||
|
||||
if (self.delegate && [_delegate respondsToSelector:@selector(tableControllerDidFinalizeLoad:)]) {
|
||||
[_delegate performSelector:@selector(tableControllerDidFinalizeLoad:) withObject:self];
|
||||
|
||||
if (![self isEmpty] && ![self isLoading]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
|
||||
}
|
||||
|
||||
if (self.delegate && [_delegate respondsToSelector:@selector(tableControllerDidFinalizeLoad:)]) {
|
||||
[self.delegate performSelector:@selector(tableControllerDidFinalizeLoad:) withObject:self];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1319,4 +1337,11 @@ static NSString * lastUpdatedDateDictionaryKey = @"lastUpdatedDateDictionaryKey"
|
||||
}
|
||||
}
|
||||
|
||||
- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation {
|
||||
NSIndexPath *indexPath = [self indexPathForObject:object];
|
||||
if (indexPath) {
|
||||
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:rowAnimation];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
@property (nonatomic, readonly) RKCache *cache;
|
||||
@property (nonatomic, retain) UIView *pullToRefreshHeaderView;
|
||||
|
||||
#pragma mark - Subclass Load Event Hooks
|
||||
|
||||
- (void)didStartLoad;
|
||||
|
||||
/**
|
||||
Must be invoked when the table controller has finished loading.
|
||||
|
||||
@@ -45,6 +49,7 @@
|
||||
and cleaning up the table overlay view.
|
||||
*/
|
||||
- (void)didFinishLoad;
|
||||
- (void)didFailLoadWithError:(NSError *)error;
|
||||
|
||||
#pragma mark - Table View Overlay
|
||||
|
||||
@@ -60,14 +65,6 @@
|
||||
- (void)pullToRefreshStateChanged:(UIGestureRecognizer *)gesture;
|
||||
- (void)resetPullToRefreshRecognizer;
|
||||
|
||||
#pragma mark - State Mutators
|
||||
|
||||
- (void)setLoading:(BOOL)loading;
|
||||
- (void)setLoaded:(BOOL)loaded;
|
||||
- (void)setEmpty:(BOOL)empty;
|
||||
- (void)setOffline:(BOOL)offline;
|
||||
- (void)setErrorState:(BOOL)error;
|
||||
|
||||
/**
|
||||
Returns a Boolean value indicating if the table controller
|
||||
should be considered empty and transitioned into the empty state.
|
||||
|
||||
@@ -22,6 +22,17 @@
|
||||
|
||||
typedef UIView *(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteger sectionIndex, NSString *sectionTitle);
|
||||
|
||||
@class RKFetchedResultsTableController;
|
||||
@protocol RKFetchedResultsTableControllerDelegate <RKAbstractTableControllerDelegate>
|
||||
|
||||
@optional
|
||||
|
||||
// Sections
|
||||
- (void)tableController:(RKFetchedResultsTableController *)tableController didInsertSectionAtIndex:(NSUInteger)sectionIndex;
|
||||
- (void)tableController:(RKFetchedResultsTableController *)tableController didDeleteSectionAtIndex:(NSUInteger)sectionIndex;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
Instances of RKFetchedResultsTableController provide an interface for driving a UITableView
|
||||
*/
|
||||
@@ -33,6 +44,7 @@ typedef UIView *(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUInteg
|
||||
BOOL _isEmptyBeforeAnimation;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) id<RKFetchedResultsTableControllerDelegate> delegate;
|
||||
@property (nonatomic, retain, readonly) NSFetchedResultsController *fetchedResultsController;
|
||||
@property (nonatomic, copy) NSString *resourcePath;
|
||||
@property (nonatomic, retain) NSFetchRequest *fetchRequest;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKFetchedResultsTableController.h"
|
||||
#import "RKAbstractTableController_Internals.h"
|
||||
#import "RKManagedObjectStore.h"
|
||||
@@ -33,12 +34,13 @@
|
||||
@interface RKFetchedResultsTableController ()
|
||||
@property (nonatomic, retain, readwrite) NSFetchedResultsController *fetchedResultsController;
|
||||
|
||||
- (void)performFetch;
|
||||
- (BOOL)performFetch:(NSError **)error;
|
||||
- (void)updateSortedArray;
|
||||
@end
|
||||
|
||||
@implementation RKFetchedResultsTableController
|
||||
|
||||
@dynamic delegate;
|
||||
@synthesize fetchedResultsController = _fetchedResultsController;
|
||||
@synthesize resourcePath = _resourcePath;
|
||||
@synthesize heightForHeaderInSection = _heightForHeaderInSection;
|
||||
@@ -77,19 +79,31 @@
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (void)performFetch {
|
||||
- (BOOL)performFetch:(NSError **)error {
|
||||
// TODO: We could be doing a KVO on the predicate/sortDescriptors/sectionKeyPath and intelligently deleting the cache
|
||||
[NSFetchedResultsController deleteCacheWithName:_fetchedResultsController.cacheName];
|
||||
|
||||
NSError* error;
|
||||
BOOL success = [_fetchedResultsController performFetch:&error];
|
||||
BOOL success = [_fetchedResultsController performFetch:error];
|
||||
if (!success) {
|
||||
self.error = error;
|
||||
RKLogError(@"performFetch failed with error: %@", [error localizedDescription]);
|
||||
RKLogError(@"performFetch failed with error: %@", [*error localizedDescription]);
|
||||
return NO;
|
||||
} else {
|
||||
RKLogTrace(@"performFetch completed successfully");
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
|
||||
for (NSUInteger index = 0; index < [self sectionCount]; index++) {
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didInsertSectionAtIndex:)]) {
|
||||
[self.delegate tableController:self didInsertSectionAtIndex:index];
|
||||
}
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didInsertObject:atIndexPath:)]) {
|
||||
for (NSUInteger row = 0; row < [self numberOfRowsInSection:index]; row++) {
|
||||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:index];
|
||||
id object = [self objectForRowAtIndexPath:indexPath];
|
||||
[self.delegate tableController:self didInsertObject:object atIndexPath:indexPath];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)updateSortedArray {
|
||||
@@ -238,10 +252,14 @@
|
||||
[_fetchedResultsController release];
|
||||
_fetchedResultsController.delegate = self;
|
||||
|
||||
|
||||
[self performFetch];
|
||||
// Perform the load
|
||||
NSError *error;
|
||||
[self didStartLoad];
|
||||
BOOL success = [self performFetch:&error];
|
||||
if (! success) {
|
||||
[self didFailLoadWithError:error];
|
||||
}
|
||||
[self updateSortedArray];
|
||||
|
||||
[self.tableView reloadData];
|
||||
[self didFinishLoad];
|
||||
|
||||
@@ -512,7 +530,7 @@
|
||||
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller {
|
||||
RKLogTrace(@"Beginning updates for fetchedResultsController (%@). Current section count = %d (resource path: %@)", controller, [[controller sections] count], _resourcePath);
|
||||
|
||||
if(_sortSelector) return;
|
||||
if (_sortSelector) return;
|
||||
|
||||
[self.tableView beginUpdates];
|
||||
_isEmptyBeforeAnimation = [self isEmpty];
|
||||
@@ -523,17 +541,25 @@
|
||||
atIndex:(NSUInteger)sectionIndex
|
||||
forChangeType:(NSFetchedResultsChangeType)type {
|
||||
|
||||
if(_sortSelector) return;
|
||||
if (_sortSelector) return;
|
||||
|
||||
switch (type) {
|
||||
case NSFetchedResultsChangeInsert:
|
||||
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didInsertSectionAtIndex:)]) {
|
||||
[self.delegate tableController:self didInsertSectionAtIndex:sectionIndex];
|
||||
}
|
||||
break;
|
||||
|
||||
case NSFetchedResultsChangeDelete:
|
||||
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didDeleteSectionAtIndex:)]) {
|
||||
[self.delegate tableController:self didDeleteSectionAtIndex:sectionIndex];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -548,7 +574,7 @@
|
||||
forChangeType:(NSFetchedResultsChangeType)type
|
||||
newIndexPath:(NSIndexPath *)newIndexPath {
|
||||
|
||||
if(_sortSelector) return;
|
||||
if (_sortSelector) return;
|
||||
|
||||
NSIndexPath* adjIndexPath = [self indexPathForFetchedResultsIndexPath:indexPath];
|
||||
NSIndexPath* adjNewIndexPath = [self indexPathForFetchedResultsIndexPath:newIndexPath];
|
||||
@@ -595,13 +621,12 @@
|
||||
|
||||
[self updateSortedArray];
|
||||
|
||||
if(_sortSelector) {
|
||||
if (_sortSelector) {
|
||||
[self.tableView reloadData];
|
||||
} else {
|
||||
[self.tableView endUpdates];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
|
||||
[self didFinishLoad];
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@
|
||||
|
||||
@optional
|
||||
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didInsertSection:(RKTableSection *)section atIndex:(NSUInteger)sectionIndex;
|
||||
- (void)tableController:(RKAbstractTableController *)tableController didRemoveSection:(RKTableSection *)section atIndex:(NSUInteger)sectionIndex;
|
||||
- (void)tableController:(RKTableController *)tableController didLoadObjects:(NSArray *)objects inSection:(RKTableSection *)section;
|
||||
|
||||
@end
|
||||
|
||||
@@ -50,9 +49,6 @@
|
||||
- (void)loadObjects:(NSArray *)objects inSection:(NSUInteger)sectionIndex;
|
||||
- (void)loadEmpty;
|
||||
|
||||
// Move to superclass???
|
||||
- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation;
|
||||
|
||||
/**
|
||||
Load an array of RKTableItems into table cells of the specified class. A table cell
|
||||
mapping will be constructed on your behalf and yielded to the block for configuration.
|
||||
@@ -134,7 +130,6 @@
|
||||
Returns the first section with the specified header title.
|
||||
@param title The header title.
|
||||
*/
|
||||
// MOVED
|
||||
- (RKTableSection *)sectionWithHeaderTitle:(NSString *)title;
|
||||
|
||||
/**
|
||||
@@ -143,7 +138,6 @@
|
||||
@param section Must be a valid non nil RKTableViewSection.
|
||||
@return The index of the given section if contained within the receiver, otherwise NSNotFound.
|
||||
*/
|
||||
// MOVED
|
||||
- (NSUInteger)indexForSection:(RKTableSection *)section;
|
||||
|
||||
// Coalesces a series of table view updates performed within the block into
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
[self.sections removeObjectsAtIndexes:indexes];
|
||||
}
|
||||
|
||||
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects {
|
||||
- (void)replaceSectionsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects {
|
||||
[self.sections replaceObjectsAtIndexes:indexes withObjects:objects];
|
||||
}
|
||||
|
||||
@@ -98,11 +98,6 @@
|
||||
}
|
||||
|
||||
[[self sectionsProxy] addObject:section];
|
||||
|
||||
// TODO: move into KVO?
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didInsertSection:atIndex:)]) {
|
||||
[self.delegate tableController:self didInsertSection:section atIndex:[self.sections indexOfObject:section]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeSection:(RKTableSection *)section {
|
||||
@@ -112,10 +107,6 @@
|
||||
reason:@"Tables must always have at least one section"
|
||||
userInfo:nil];
|
||||
}
|
||||
NSUInteger index = [self.sections indexOfObject:section];
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
|
||||
[self.delegate tableController:self didRemoveSection:section atIndex:index];
|
||||
}
|
||||
[[self sectionsProxy] removeObject:section];
|
||||
}
|
||||
|
||||
@@ -123,10 +114,6 @@
|
||||
NSAssert(section, @"Cannot insert a nil section");
|
||||
section.tableController = self;
|
||||
[[self sectionsProxy] insertObject:section atIndex:index];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didInsertSection:atIndex:)]) {
|
||||
[self.delegate tableController:self didInsertSection:section atIndex:index];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeSectionAtIndex:(NSUInteger)index {
|
||||
@@ -135,21 +122,10 @@
|
||||
reason:@"Tables must always have at least one section"
|
||||
userInfo:nil];
|
||||
}
|
||||
RKTableSection* section = [self.sections objectAtIndex:index];
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
|
||||
[self.delegate tableController:self didRemoveSection:section atIndex:index];
|
||||
}
|
||||
[[self sectionsProxy] removeObjectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)removeAllSections:(BOOL)recreateFirstSection {
|
||||
NSUInteger sectionCount = [self.sections count];
|
||||
for (NSUInteger index = 0; index < sectionCount; index++) {
|
||||
RKTableSection* section = [self.sections objectAtIndex:index];
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didRemoveSection:atIndex:)]) {
|
||||
[self.delegate tableController:self didRemoveSection:section atIndex:index];
|
||||
}
|
||||
}
|
||||
[[self sectionsProxy] removeAllObjects];
|
||||
|
||||
if (recreateFirstSection) {
|
||||
@@ -204,7 +180,9 @@
|
||||
|
||||
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:self.defaultRowAnimation];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RKTableControllerDidLoadObjectsNotification object:self];
|
||||
if ([self.delegate respondsToSelector:@selector(tableController:didLoadObjects:inSection:)]) {
|
||||
[self.delegate tableController:self didLoadObjects:objects inSection:section];
|
||||
}
|
||||
|
||||
// The load is finalized via network callbacks for
|
||||
// dynamic table controllers
|
||||
@@ -348,13 +326,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)reloadRowForObject:(id)object withRowAnimation:(UITableViewRowAnimation)rowAnimation {
|
||||
NSIndexPath *indexPath = [self indexPathForObject:object];
|
||||
if (indexPath) {
|
||||
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:rowAnimation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
if ([keyPath isEqualToString:@"sections"]) {
|
||||
|
||||
Reference in New Issue
Block a user