Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initally visible cells gets invisible after calling reloadSections:withRowAnimation: method

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?

like image 274
Behlül Avatar asked Jun 28 '10 12:06

Behlül


4 Answers

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:

  1. 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:

  2. Avoid reloading index paths of static cells - instead do [UIView transitionWithView:self.myStaticCell duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:nil]

like image 134
Accatyyc Avatar answered Nov 18 '22 22:11

Accatyyc


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.

like image 43
vakio Avatar answered Nov 18 '22 23:11

vakio


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:

iphone app screenshot

Only way I have found to fix it is to just use reloadData instead of reloadSections:withRowAnimation:.

like image 20
Ben Mosher Avatar answered Nov 18 '22 22:11

Ben Mosher


Adding a call to reloadData after the call to reloadSections:withRowAnimation: appears to fix the disappearing cell problem without affecting the animation.

like image 43
Frank Schmitt Avatar answered Nov 18 '22 21:11

Frank Schmitt