Augustyniak / RATreeView

Library providing easy-to-use interface for displaying tree structures on iOS and tvOS.
MIT License
2.49k stars 465 forks source link

Auto collapse same level item when deselect another one #176

Closed buithuyen closed 4 years ago

buithuyen commented 8 years ago

I have a tree as bellow:

1
2
  21
    211
    212
    213
  22
    221
    222
    223
  23
    231
    232
    233

When I deselected any item of level 2 (21,22 or 23) I would like the other item at the same level auto collapse too. I have tried with this function:

    - (void)collapseSameLevelItem:(Object*)item {
        if (item.level > 1) {
            Object* parentItem = [self.treeView parentForItem:item];
            for (Object* category in parentItem.children) {
                if ([self.treeView isCellForItemExpanded:category]) {
                    [self.treeView collapseRowForItem:category];

                    RATableViewCell* sameLevelCell = (RATableViewCell*)[self.treeView cellForItem:item];
                    [sameLevelCell setIsExpanded:NO];
                }
            }
        }
    }

But I realize that isCellForItemExpanded and collapseRowForItem function did not work as I experted.

The indexPath that I got at - (void)collapseRowForItem:(id)item collapseChildren:(BOOL)collapseChildren withRowAnimation:(RATreeViewRowAnimation)animation:

<NSIndexPath: 0x7f89be1170e0> {length = 2, path = 0 - 9223372036854775807}

Do you guys have any suggestion for me in this case? Thanks!