【发布时间】:2017-02-07 16:11:15
【问题描述】:
我需要在最多 2 个级别的可扩展表格视图中显示来自 Web 服务的数据。虽然这对于静态数据是可能的,但我无法找到一种方法来处理从后端检索到的数据。 Postman 中的一个示例如下所示:
One Level UITableView Data in Postman
以上内容仅用于一级扩展。在这里,“会计”是主要类别,“jj 标签”、“认证公众”和“一般服务”是展开后可见的子类别(一旦用户点击名为“会计”的单元格)。同样,需要显示几个类别,并且可能包含也可能不包含第二级的进一步扩展。
至于网络服务,我可以选择以两种方式获取数据:
- 在一个 API 中同时获取主类别和子类别(如上面的屏幕截图所示)。
- 在不同的 API 中获取主类别和子类别。
到目前为止,我已经尝试实现titleForHeaderInSection 中的主要类别和cellForRowAtIndexPath 中的一级子类别
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[subCatArray objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ceLL" forIndexPath:indexPath];
cell.textLabel.text = [[subCatArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [catArray count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
for (int i=0; i<[catArray count]; i++) {
if(section == i){
return NSLocalizedString([catArray objectAtIndex:i], nil);
}
}
return nil;
}
但是我该如何进行第二级并使这些可折叠/可扩展?
【问题讨论】:
标签: ios objective-c expandable-table