I want to display a table which has multiple sections and initally only 3 elements of sections are shown. When user taps the section footer, section footer gets lost (becomes nil) and all elements of that section will be shown to user.
For this reason, when the user taps the section footer, I call below code:
-(void)loadMoreRowsInSection:(NSInteger)section {
[groupStates replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:YES]];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:NO];
}
I have the following code to show section footer or not:
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
int count = [[(NSDictionary*)[filters objectAtIndex:section] valueForKeyPath:@"values.value"] count];
if (count>3&&![[groupStates objectAtIndex:section] boolValue]) {
LoadMoreFooter* loadMoreFooter = [[LoadMoreFooter alloc] initWithParent:self Section:section];
return [loadMoreFooter view];
}
else return nil;
}
When user taps the section footer and loadMoreRowsInSection function is called, this section is reloaded but the current rows of that section disappear. When I scroll up down, making the rows go out of the screen and in again, rows appear again.
If I call reloadData
instead of reloadSections:withRowAnimation:
, there is no problem but it does not seem to be a good idea to reload all the table. Plus there is no animation in reloadTable.
Has anyone encountered this problem?
Is this a "static" cell in the sense that you're keeping a reference to it yourself? In that case, the problem is probably this:
When you do an animated reload, the table view will fade out existing cells while at the same time fading in the new cells. The problem is that when the "new" cell is the exact same cell as the old one, the same cell will both fade in and fade out at the same time! And in your case, the fade out animation takes precedence and the cell is hidden.
Here are some possible solutions:
Instead of static cells, have a reusable "wrapper cell" subclass - a cell whose only purpose is to contain a wrapped view. Then, keep static references to views instead, and add them to a dequeued wrapper cell in cellForRowAtIndexPath:
Avoid reloading index paths of static cells - instead do [UIView transitionWithView:self.myStaticCell duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:nil]
I had this problem also. I used UITableViewRowAnimationNone
instead, which still animates the section for some reason (which reloadData
does not do) but it also displays it correctly after the animation.
I had a similar problem where the section headers would get stuck painted wherever they were. Although my issue persists even when scrolled on/off the screen:
Only way I have found to fix it is to just use reloadData
instead of reloadSections:withRowAnimation:
.
Adding a call to reloadData
after the call to reloadSections:withRowAnimation:
appears to fix the disappearing cell problem without affecting the animation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With