当前位置: 首页 > 工具软件 > RATreeView > 使用案例 >

RATreeView

华浩壤
2023-12-01
  RATreeView *treeView = [[RATreeView alloc]initWithFrame:CGRectMake(0,0 , kScreenWidth, kScreenHeight - NAVIGATIONBAR_H)];
    treeView.delegate = self;
    treeView.dataSource = self;
    treeView.separatorStyle = RATreeViewCellSeparatorStyleSingleLine;
    treeView.rowHeight = 44.0;
    treeView.treeFooterView = [[UIView alloc]init];
    [treeView registerClass:[KnowLedageCell class] forCellReuseIdentifier:knowLedageCell];

    [self.view addSubview:treeView];


#pragma mark -- RAtreeViewDelegate
-(void)treeView:(RATreeView *)treeView didSelectRowForItem:(id)item{
    if (self.currentModel) {
        self.currentModel.checked = !self.currentModel.checked;
        [treeView reloadRowsForItems:@[self.currentModel] withRowAnimation:RATreeViewRowAnimationAutomatic];
        
    }
    self.currentModel.checked = NO;
    KnowledgeModel *model = (KnowledgeModel*)item;
    model.checked = !model.checked;
    self.currentModel = model;
    [treeView reloadRowsForItems:@[self.currentModel] withRowAnimation:RATreeViewRowAnimationAutomatic];
    if (model.children.count == 0) {
        if (self.result) {
            self.result(model.categoryName, model.identifier);
        }
        if (!self.isBest) {
        [self.navigationController popViewControllerAnimated:YES];
        }
        
        
       
    }
}
#pragma mark LeftTreeView DataSource

- (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item {
    
    return 44;
}
-(UITableViewCell *)treeView:(RATreeView *)treeView cellForItem:(id)item{
    KnowledgeModel *model = (KnowledgeModel*)item;
    KnowLedageCell *cell = [treeView dequeueReusableCellWithIdentifier:knowLedageCell];
    cell.model = model;
    if (model.children.count == 0) {
        if (model.checked) {
             cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }else{
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
    }
    return cell;
}

- (NSInteger)treeView:(RATreeView *)treeView numberOfChildrenOfItem:(id)item {
    KnowledgeModel *model = (KnowledgeModel*)item;
    if (item == nil) {
        
        return self.datas.count;
        
    }
    return model.children.count;
}
//此回调方法跟上面的方法是关联着的
- (id)treeView:(RATreeView *)treeView child:(NSInteger)index ofItem:(id)item {
    KnowledgeModel *model = (KnowledgeModel*)item;
    if (item == nil) {
        return [self.datas objectAtIndex:index];
    }
    return model.children[index];
}

 类似资料:

相关阅读

相关文章

相关问答