如何在ios中创建像Tree Structure一样的可扩展表视图

Tes*_*est 10 objective-c uitableview expandablelistview ios swift

在每一个我需要一个可扩展的表格视图我的数据,是否可以在tableView中创建这样的.在我的数据每个有不同的孩子,下面是我的数据

-A1
    -A1.1
        -A1.1.1
            A1.1.1.1
+B1
+C1
+D1

----------------------
+A1
-B1
    +B1.1
+C1
+D1
-----------------------
+A1
+B1
+C1
-D1
    +D1.1
    -D1.2
        +D1.2.1
        +D1.2.2
    +D1.3
Run Code Online (Sandbox Code Playgroud)

提前谢谢你

小智 2

尝试这个 :-

  NSMutableIndexSet *expandedSections;
  @property (strong, nonatomic) NSIndexPath *expandedIndexPath;



 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
   {

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
        return 100;
    }
    else
    {
    return 30;
    }

}


  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {

  [tableView deselectRowAtIndexPath:indexPath animated:YES];
  if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
      [tableView beginUpdates];
      self.expandedIndexPath = nil;
      [tableView endUpdates];
  }
  else{
      self.expandedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];

      [tableView beginUpdates];

     if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame)     {
        self.expandedIndexPath = indexPath;
    } else {
        self.expandedIndexPath = nil;
    }

    [tableView endUpdates];
   }

 }
Run Code Online (Sandbox Code Playgroud)