Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue where grouping objects by section in RKTableController and …

…loading an empty collection would fail to refresh table view.
  • Loading branch information...
commit 8647fa5f428b3a1f25ac809ddd3a4c876d73c333 1 parent fa88dd4
@blakewatters blakewatters authored
View
3  Code/UI/RKTableController.m
@@ -314,6 +314,9 @@ - (void)objectLoader:(RKObjectLoader *)loader didLoadObjects:(NSArray *)objects
if (self.sectionNameKeyPath) {
NSArray *sectionedObjects = [objects sectionsGroupedByKeyPath:self.sectionNameKeyPath];
+ if ([sectionedObjects count] == 0) {
+ [self removeAllSections];
+ }
for (NSArray *sectionOfObjects in sectionedObjects) {
NSUInteger sectionIndex = [sectionedObjects indexOfObject:sectionOfObjects];
if (sectionIndex >= [self sectionCount]) {
View
37 Tests/Application/UI/RKTableControllerTest.m
@@ -706,6 +706,43 @@ - (void)testLoadCollectionOfObjectsAndMapThemIntoSections {
assertThatInt(tableController.rowCount, is(equalToInt(3)));
}
+- (void)testLoadingACollectionOfObjectsIntoSectionsAndThenLoadingAnEmptyCollectionChangesTableToEmpty {
+ RKObjectManager* objectManager = [RKTestFactory objectManager];
+ objectManager.client.cachePolicy = RKRequestCachePolicyNone;
+ RKTableControllerTestTableViewController* viewController = [RKTableControllerTestTableViewController new];
+ RKTableController* tableController = [RKTableController tableControllerForTableViewController:viewController];
+ tableController.objectManager = objectManager;
+ [tableController mapObjectsWithClass:[RKTestUser class] toTableCellsWithMapping:[RKTableViewCellMapping cellMappingUsingBlock:^(RKTableViewCellMapping* mapping) {
+ mapping.cellClass = [RKTestUserTableViewCell class];
+ [mapping mapKeyPath:@"name" toAttribute:@"textLabel.text"];
+ [mapping mapKeyPath:@"nickName" toAttribute:@"detailTextLabel.text"];
+ }]];
+ tableController.sectionNameKeyPath = @"name";
+ RKTableControllerTestDelegate* delegate = [RKTableControllerTestDelegate tableControllerDelegate];
+ delegate.timeout = 10;
+ tableController.delegate = delegate;
+ [tableController loadTableFromResourcePath:@"/JSON/users.json" usingBlock:^(RKObjectLoader* objectLoader) {
+ objectLoader.objectMapping = [RKObjectMapping mappingForClass:[RKTestUser class] usingBlock:^(RKObjectMapping* mapping) {
+ [mapping mapAttributes:@"name", nil];
+ }];
+ }];
+ [delegate waitForLoad];
+ assertThatBool([tableController isLoaded], is(equalToBool(YES)));
+ assertThatInt(tableController.sectionCount, is(equalToInt(3)));
+ assertThatInt(tableController.rowCount, is(equalToInt(3)));
+ delegate = [RKTableControllerTestDelegate tableControllerDelegate];
+ delegate.timeout = 10;
+ tableController.delegate = delegate;
+ [tableController loadTableFromResourcePath:@"/204" usingBlock:^(RKObjectLoader* objectLoader) {
+ objectLoader.objectMapping = [RKObjectMapping mappingForClass:[RKTestUser class] usingBlock:^(RKObjectMapping* mapping) {
+ [mapping mapAttributes:@"name", nil];
+ }];
+ }];
+ [delegate waitForLoad];
+ assertThatBool([tableController isLoaded], is(equalToBool(YES)));
+ assertThatBool([tableController isEmpty], is(equalToBool(YES)));
+}
+
#pragma mark - RKTableViewDelegate Tests
- (void)testNotifyTheDelegateWhenLoadingStarts {
View
6 Tests/Server/server.rb
@@ -99,6 +99,12 @@ def render_fixture(path, options = {})
content_type 'application/json'
"".to_json
end
+
+ get '/204' do
+ status 204
+ content_type 'application/json'
+ "".to_json
+ end
get '/403' do
status 403
Please sign in to comment.
Something went wrong with that request. Please try again.