Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collapsing Cell which has more rows than tableView.visibleRows.Count #1

Open
ghost opened this issue Apr 18, 2013 · 3 comments
Open

Comments

@ghost
Copy link

ghost commented Apr 18, 2013

First of all, i'd like to thank you for this great component.
and here is the bug;

If you expand a cell which has more ancestorSubItems than the visibleRows count of the tableView and try to collapse that cell back; it gives invalid update error.

'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (6) must be equal to the number of rows contained in that section before the update (14), plus or minus the number of rows inserted or deleted from that section (0 inserted, 7 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Also recreated this situation with your example code too (Just added more subItems and expanded/collapsed)

any idea how to fix that situation?

@mikaelbartlett
Copy link

cellForRowAtIndexPath return nil if the cell isn't visible.

use the array to fetch the right item instead.

@fei545
Copy link

fei545 commented Sep 10, 2015

1、replace this method

  • (NSMutableArray *)removeIndexPathForTreeItems:(NSMutableArray *)treeItemsToRemove {
    NSMutableArray *result = [NSMutableArray array];

    for (NSInteger i = 0; i < self.treeItems.count; ++i) {

    KOTreeItem* treeItem = [self.treeItems objectAtIndex:i];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:treeItem.row inSection:0];
    
        for (KOTreeItem *tmpTreeItem in treeItemsToRemove)
        {
    
            if ([treeItem isEqualToSelectingItem:tmpTreeItem])
            {
                [_itemBeRemoved addObject:treeItem];
                [result addObject:indexPath];
            }
        }
    

    }

    return result;
    }

2、change this method

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    .......
    for (NSInteger i = 0 ;i<self.treeItems.count;i++) {
    KOTreeItem *tmpTreeItem = [self.treeItems objectAtIndex:i];
    tmpTreeItem.row = i;
    }

    for (KOTreeItem * ti in _itemBeRemoved ) {
    NSIndexPath * ip = [NSIndexPath indexPathForRow:ti.row inSection:0];
    [removeIndexPaths addObject:ip];
    }

    if ([removeIndexPaths count]) {
    [treeTableView deleteRowsAtIndexPaths:removeIndexPaths withRowAnimation:UITableViewRowAnimationBottom];
    [_itemBeRemoved removeAllObjects];
    }
    }

3、add a property named row to KOTreeItem
@Property (nonatomic) NSInteger row;

@chesteryeum
Copy link

does anybody have a working version that fixes the "invalid number of rows" issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants