File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Tests/FZAccordionTableViewUnitTests Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,15 @@ - (void)setDataSource:(id<UITableViewDataSource>)dataSource {
150
150
super.dataSource = self;
151
151
}
152
152
153
+ - (void )insertSections : (NSIndexSet *)sections withRowAnimation : (UITableViewRowAnimation)animation {
154
+ [sections enumerateIndexesUsingBlock: ^(NSUInteger section, BOOL * _Nonnull stop) {
155
+ FZAccordionTableViewSectionInfo *sectionInfo = [[FZAccordionTableViewSectionInfo alloc ] initWithNumberOfRows: 0 ];
156
+ [self .sectionInfos insertObject: sectionInfo atIndex: section];
157
+ }];
158
+
159
+ [super insertSections: sections withRowAnimation: animation];
160
+ }
161
+
153
162
- (void )deleteSections : (NSIndexSet *)sections withRowAnimation : (UITableViewRowAnimation)animation {
154
163
155
164
// Remove section info in reverse order to prevent array from
@@ -431,7 +440,11 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
431
440
432
441
[self .sectionInfos[section] setNumberOfRows: numOfRows];
433
442
434
- return ([self isSectionOpen: section]) ? numOfRows : 0 ;
443
+ if (![self isSectionOpen: section]) {
444
+ numOfRows = 0 ;
445
+ }
446
+
447
+ return numOfRows;
435
448
}
436
449
437
450
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
Original file line number Diff line number Diff line change @@ -203,6 +203,32 @@ - (void)testAddingSection {
203
203
XCTAssert (initialSectionCount+1 == self.tableView .numberOfSections , @" The section counts should match up." );
204
204
}
205
205
206
+ - (void )testAddingSectionWhileOtherSectionsAreOpen {
207
+
208
+ // First, open all of the sections
209
+ self.tableView .allowMultipleSectionsOpen = YES ;
210
+ for (NSInteger i = 0 ; i < [self .tableView numberOfSections ]; i++) {
211
+ [self waitForHeaderViewInSection: i];
212
+ [self .tableView toggleSection: i];
213
+
214
+ XCTAssert ([self .tableView isSectionOpen: i], @" Section %d should be open." , (int )i);
215
+ }
216
+
217
+ NSInteger section = 1 ;
218
+ NSInteger numberOfRows = 33 ;
219
+ NSInteger initialSectionCount = self.mainViewController .sections .count ;
220
+
221
+ // Add data into data source
222
+ [self .mainViewController.sections insertObject: @(numberOfRows) atIndex: section];
223
+
224
+ // Add to tableview
225
+ NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: section];
226
+ [self .tableView insertSections: indexSet withRowAnimation: UITableViewRowAnimationFade];
227
+
228
+ XCTAssert ([self .mainViewController.sections[section] integerValue ] == [self .tableView.sectionInfos[section] numberOfRows ], @" The data source section rows should match up." );
229
+ XCTAssert (initialSectionCount+1 == self.tableView .numberOfSections , @" The section counts should match up." );
230
+ }
231
+
206
232
#pragma mark - Delete Section -
207
233
208
234
- (void )testDeleteClosedSection {
You can’t perform that action at this time.
0 commit comments