Skip to content

Commit

Permalink
Handle inserting new sections case for BIDatasourceFeedTableView
Browse files Browse the repository at this point in the history
  • Loading branch information
mardelean committed Jan 10, 2016
1 parent 69038fc commit 3eef16f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions BIObjCHelpers/Batch/BIBatchResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef NS_OPTIONS(NSUInteger, BIBatchResponseOptions) {

@property (nonatomic, strong, nullable, readonly) NSError *error;
@property (nonatomic, copy, nullable, readonly) NSArray *indexPaths;
@property (nonatomic, copy, nullable, readonly) NSIndexSet *addedSectionsIndexSet;
@property (nonatomic, strong, nullable, readonly) BIBatchRequest *batchRequest;
/*!
* Extra response values.
Expand Down Expand Up @@ -106,6 +107,12 @@ typedef NS_OPTIONS(NSUInteger, BIBatchResponseOptions) {
*/
@property (nonatomic, copy, nullable, readwrite) NSArray *indexPaths;

/*!
* @brief Contains NSUINteger type objects for defining whether there are new sections to be inserted
* Not nil only if error is nil
*/
@property (nonatomic, copy, nullable, readwrite) NSIndexSet *addedSectionsIndexSet;

/*!
* @brief Original request.
*/
Expand Down
6 changes: 5 additions & 1 deletion BIObjCHelpers/Batch/BIBatchResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ @interface BIBatchResponse ()

@property (nonatomic, strong, nullable, readwrite) NSError *error;
@property (nonatomic, copy, nullable, readwrite) NSArray *indexPaths;
@property (nonatomic, copy, nullable, readwrite) NSIndexSet *addedSectionsIndexSet;
@property (nonatomic, strong, nullable, readwrite) BIBatchRequest *batchRequest;
@property (nonatomic, assign, readwrite) BIBatchResponseOptions options;

Expand All @@ -29,7 +30,8 @@ - (nonnull BIBatchResponse *)copyWithZone:(NSZone *)zone {
copy.indexPaths = self.indexPaths;
copy.options = self.options;
copy.batchRequest = [self.batchRequest copy];

copy.addedSectionsIndexSet = self.addedSectionsIndexSet;

return copy;
}

Expand All @@ -41,6 +43,7 @@ - (nonnull instancetype)mutableCopyWithZone:(NSZone *)zone {
mutableCopy.error = self.error;
mutableCopy.indexPaths = self.indexPaths;
mutableCopy.options = self.options;
mutableCopy.addedSectionsIndexSet = self.addedSectionsIndexSet;

return mutableCopy;
}
Expand Down Expand Up @@ -82,6 +85,7 @@ @implementation BIMutableBatchResponse
@dynamic indexPaths;
@dynamic batchRequest;
@dynamic options;
@dynamic addedSectionsIndexSet;

#pragma mark - Factory methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ - (void)handleFetchBatchResponseWithFailure:(nonnull BIBatchResponse *)batchResp
- (void)handleFetchBatchResponseWithSuccess:(nonnull BIBatchResponse *)batchResponse {
if (batchResponse.indexPaths.count) {
[self.tableView beginUpdates];
if (batchResponse.addedSectionsIndexSet.count) {
[self.tableView insertSections:batchResponse.addedSectionsIndexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}
[self.tableView insertRowsAtIndexPaths:batchResponse.indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
Expand Down

0 comments on commit 3eef16f

Please sign in to comment.