RATreeView icon indicating copy to clipboard operation
RATreeView copied to clipboard

How can I set all the cells default state to expanded?

Open gwpp opened this issue 9 years ago • 16 comments

Hi, first thank you very much for your RATreeView. I use the latest version 1.0.3,Its default state for all of cells is collapsed,can I change it to expanded the default state?How can I do? Please help,thank you,looking forward to your reply

gwpp avatar Jun 21 '15 14:06 gwpp

+1

zvving avatar Jun 24 '15 07:06 zvving

I am looking for that too ! Thank you.

iDevelopper avatar Jul 01 '15 14:07 iDevelopper

[_treeView reloadData];
for (id item in [_treeView itemsForRowsInRect:_treeView.frame]) {
    [_treeView expandRowForItem:item expandChildren:YES withRowAnimation:RATreeViewRowAnimationNone];
}

iDevelopper avatar Jul 02 '15 08:07 iDevelopper

OK, I understand, thank you very much.

gwpp avatar Jul 17 '15 01:07 gwpp

thank you very much first, i got the code above ,however the treeview expanded with animation still,please helpe

songzhen90 avatar Oct 29 '15 09:10 songzhen90

Well done.Thanks.

zuo305 avatar Nov 26 '15 06:11 zuo305

thank you very much first, i got the code above ,however the treeview expanded with animation still,please help.

+1

shenguanjiejie avatar Dec 01 '15 03:12 shenguanjiejie

I set _treeView.rowsExpandingAnimation = RATreeViewRowAnimationNone; _treeView.rowsCollapsingAnimation = RATreeViewRowAnimationNone;

treeView with animation still.

shenguanjiejie avatar Dec 01 '15 03:12 shenguanjiejie

Something a little better:

- (void)reloadData
{
    _treeView.hidden = YES;
    [_treeView reloadData];
    [UIView animateWithDuration:0. animations:^{
        for (id item in [_treeView itemsForRowsInRect:_treeView.frame]) {
            [_treeView expandRowForItem:item expandChildren:YES withRowAnimation:RATreeViewRowAnimationNone];
        }
    } completion:^(BOOL finished) {
        _treeView.hidden = NO;
    }];
}

Hope it help!

iDevelopper avatar Dec 01 '15 06:12 iDevelopper

Have a try my way:

id itemBefore = [[_treeView itemsForVisibleRows] firstObject];
[_treeView reloadData];

NSArray *array = [_treeView itemsForRowsInRect:_treeView.frame];
if(array.count > 0){
    for (id item in array) {
        if ([item isKindOfClass:[DepartmentInfo class]]) {
            if ([item isExpand]) {
                [_treeView expandRowForItem:item expandChildren:NO withRowAnimation:RATreeViewRowAnimationNone];
            }
        }
    }
    [_treeView scrollToRowForItem: itemBefore atScrollPosition:RATreeViewScrollPositionTop animated:NO];
}

shenguanjiejie avatar Dec 01 '15 07:12 shenguanjiejie

I set _treeView.rowsExpandingAnimation = RATreeViewRowAnimationNone; _treeView.rowsCollapsingAnimation = RATreeViewRowAnimationNone;

treeView with animation still.

Each time you modify you RATreeView organise the code responsible for the changes in the way presented below:

[treeView beginUpdates];
//modify your tree view here
[UIView performWithoutAnimation:^{
   [treeView endUpdates];
}];

It works for me - I had the same issue with the UITableView itself.

Augustyniak avatar Dec 01 '15 07:12 Augustyniak

Dear Augustyniak , Thank you very much!!!!!!! 👍

shenguanjiejie avatar Dec 01 '15 07:12 shenguanjiejie

nice work, thanks you

fukemy avatar Feb 03 '18 11:02 fukemy

hello. now im working in swift, can u provide this expand code using swift 4?

fukemy avatar Jul 28 '18 18:07 fukemy

i got this problem screen shot 2018-07-29 at 02 01 22

fukemy avatar Jul 28 '18 19:07 fukemy

how to get indexPathForItem in RATreeview swift version. It's not working

thiwankacs avatar Sep 18 '18 12:09 thiwankacs