[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];
}