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

expand to the target item? #229

Closed DingSoung closed 7 years ago

DingSoung commented 7 years ago

for example, expand to 3.2 directly, not expand 1 then 2.2

DingSoung commented 7 years ago

I fixed by get the array of items to expand

example

+ (NSArray<Model*> * _Nullable)subModelsWithUniqueID:(NSString * _Nullable)uniqueID models:(NSArray<Model *> * _Nullable)models {
    for (Model *model in models) {
        if ([uniqueID isEqualToString:model.uniqueID]) {
            return @[model];
        }
    }
    for (Model *model in models) {
        NSArray<Model *> *subModels = [Model subModelsWithUniqueID:uniqueID models:model.subModels];
        if (subModels) {
            return [@[model] arrayByAddingObjectsFromArray: subModels];
        }
    }
    return nil;
}
NSArray<Model *> *models = [Model subModelsWithUniqueID:model.uniqueID  models:_self.models];
for (int i = 0; i < models.count; i++) {
     [_self.treeView expandRowForItem:models[i] expandChildren:NO withRowAnimation:RATreeViewRowAnimationAutomatic];
}