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

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

Open gwpp opened 9 years ago

gwpp commented 9 years ago

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

zvving commented 9 years ago

+1

iDevelopper commented 9 years ago

I am looking for that too ! Thank you.

iDevelopper commented 9 years ago
[_treeView reloadData];
for (id item in [_treeView itemsForRowsInRect:_treeView.frame]) {
    [_treeView expandRowForItem:item expandChildren:YES withRowAnimation:RATreeViewRowAnimationNone];
}
gwpp commented 9 years ago

OK, I understand, thank you very much.

songzhen90 commented 8 years ago

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

zuo305 commented 8 years ago

Well done.Thanks.

shenguanjiejie commented 8 years ago

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

+1

shenguanjiejie commented 8 years ago

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

treeView with animation still.

iDevelopper commented 8 years ago

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!

shenguanjiejie commented 8 years ago

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];
}
Augustyniak commented 8 years ago

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.

shenguanjiejie commented 8 years ago

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

fukemy commented 6 years ago

nice work, thanks you

fukemy commented 6 years ago

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

fukemy commented 6 years ago

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

thiwankacs commented 6 years ago

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