ios - 如何在 ios 中创建类似树结构的可扩展 TableView

标签 ios objective-c swift uitableview expandablelistview

大家好,我的数据需要一个可扩展的表格 View , 是否可以在 tableView 中这样创建。在我的数据中,每个数据都有不同的 Childs,下面是我的数据

-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

先帮帮我谢谢

最佳答案

试试这个:-

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

 }

关于ios - 如何在 ios 中创建类似树结构的可扩展 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219982/

相关文章:

SwiftUI:NavigationBarItem 前导不显示

ios - 将参数传递给作为参数的选择器

ios - 无法使用自定义类返回类型覆盖方法

ios - 在 iOS/callStackReturnAddresses 和 callStackSymbols 中调试

ios - 为什么苹果的闭包声明缺少参数标签

ios - 在 objective-c 中扩展 tableview 时按钮不起作用?

objective-c - 如何制作 AND 或 OR 表达式?

swift - 在菜单栏应用程序中拖动并调整我的 NSPopover 大小(快速)

ios - 快速实例化 UIViewController

ios - Flutter IOS应用程序不会以image_picker开头:^ 0.6.3 + 4