Open ghost opened 11 years ago
cellForRowAtIndexPath return nil if the cell isn't visible.
use the array to fetch the right item instead.
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;
does anybody have a working version that fixes the "invalid number of rows" issue?
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?