【问题标题】:Expandable tableView in iphoneiphone中的可扩展tableView
【发布时间】:2012-07-24 07:25:41
【问题描述】:

我想制作这种类型的可展开/可折叠表格视图。 如图所示,有类别和子类别。 例如,“健康与美容”是一个类别,当我单击此单元格时,其打开的子类别如下图所示。 那么如何制作这种类型的表格视图呢? 请给我建议。

【问题讨论】:

  • 对于 swift3,您可以查看本教程解释自定义可扩展和可折叠 UITableView iostutorialjunction.com/2017/03/…
  • 你可以试试这个库用于 Swift 3 -> ExpyTableView。它使您只需实现一种方法即可轻松生成可扩展的表格视图。

标签: ios iphone xcode uitableview


【解决方案1】:

最后,我在下面得到了两个非常有用的帮助链接,它们准确地描述了这里的要求 Expanding/Collapsing TableView Sections
Collapsable Table View for iOS

真的,对于这种展开/折叠的 tableview 部分的好文章

【讨论】:

【解决方案2】:

使用以下代码将单元格扩展为 UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text=[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"name"];
    [cell setIndentationLevel:[[[self.arForTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];    
    return cell;
}

展开和折叠行的代码——TableView DidSelectRow 方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *d=[self.arForTable objectAtIndex:indexPath.row];
    if([d valueForKey:@"Objects"]) {
        NSArray *ar=[d valueForKey:@"Objects"];
        BOOL isAlreadyInserted=NO;
        for(NSDictionary *dInner in ar ){
            NSInteger index=[self.arForTable indexOfObjectIdenticalTo:dInner];
            isAlreadyInserted=(index>0 && index!=NSIntegerMax);
            if(isAlreadyInserted) break; 
        }
        if(isAlreadyInserted) {
            [self miniMizeThisRows:ar];
        } else {        
            NSUInteger count=indexPath.row+1;
            NSMutableArray *arCells=[NSMutableArray array];
            for(NSDictionary *dInner in ar ) {
                [arCells addObject:[NSIndexPath indexPathForRow:count inSection:0]];
                [self.arForTable insertObject:dInner atIndex:count++];
            }
            [tableView insertRowsAtIndexPaths:arCells withRowAnimation:UITableViewRowAnimationLeft];
        }
    }
}

一种有助于最小化和最大化/展开折叠行的方法。

-(void)miniMizeThisRows:(NSArray*)ar{
    for(NSDictionary *dInner in ar ) {
        NSUInteger indexToRemove=[self.arForTable indexOfObjectIdenticalTo:dInner];        
        NSArray *arInner=[dInner valueForKey:@"Objects"];
        if(arInner && [arInner count]>0){
            [self miniMizeThisRows:arInner];
        }
        if([self.arForTable indexOfObjectIdenticalTo:dInner]!=NSNotFound) {
            [self.arForTable removeObjectIdenticalTo:dInner];
            [self.tableView deleteRowsAtIndexPaths:
              [NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexToRemove inSection:0]]
                      withRowAnimation:UITableViewRowAnimationRight];
        }
    }
}

您可以下载source code from my tutorial site

【讨论】:

    【解决方案3】:

    如果这有帮助:[访问 uitableview 的可展开和可折叠部分]https://github.com/OliverLetterer/UIExpandableTableView

    【讨论】:

    • 这里现在有这个可扩展表格视图库的 Swift 版本 -> ExpyTableView 。它没有 downloadDataForSection 和 UIExpansionState 通知器,但所有其他功能都是用 Swift 编写的并且存在于新库中。
    【解决方案4】:

    我对可扩展的表格视图有一点不同的方法 - 一种与这些表格视图的一般构建方式一致的方法。

    标题单元格标题应该是可点击的,然后标题下方的单元格显示或隐藏。这可以通过向标题添加手势识别器来实现,当点击时,您只需删除该标题(部分)下方的所有单元格,反之亦然(添加单元格)。当然,您必须维护哪些标头“打开”以及哪些标头“关闭”的状态。

    这很好有几个原因:

    1. 标题和单元格的工作是分开的,这使得代码更清晰。
    2. 此方法与表视图的构建方式(标题和单元格)配合得很好,因此没有什么神奇之处 - 代码只是删除或添加单元格,并且应该与更高版本的 iOS 兼容。李>

    我制作了一个非常简单的库来实现这一点。只要您的表格视图设置了 UITableView 部分标题和单元格,您所要做的就是子类化表格视图和标题。试试看:)

    链接:https://github.com/fuzz-productions/FZAccordionTableView

    【讨论】:

      【解决方案5】:

      尝试使用此代码...可能会有所帮助.. 并随时根据您的要求编辑代码...

      #import "ViewController.h"
      #import <QuartzCore/QuartzCore.h>
      @interface ViewController ()
      
      @end
      
      @implementation ViewController
      @synthesize myTable;
      - (void)viewDidLoad
      {
          [super viewDidLoad];
          // Do any additional setup after loading the view, typically from a nib.
          //myTable.backgroundColor=[UIColor clearColor];
         // self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.png"]];
          muArr= [[NSMutableArray alloc]initWithObjects:@"Vinay",@"Anmol",@"Jagriti", nil];
          ExpArr=[[NSMutableArray alloc]initWithObjects:@"Useeee",@"Thissss",@"Codeee", nil];
          otherExpand=100;
          checker=100;
      
      }
      
      -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
      {
          return muArr.count;
      }
      
      -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
      {
          if(otherExpand==section)
          return ExpArr.count;
      
          return  0;
      
      }
      
      -(BOOL)tableView:(UITableView *)table canCollapse:(NSIndexPath *)indexPath
      {
      
          return NO;
      }
      
      -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
          static NSString *Identifier=@"Cell";
          UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:Identifier];
          if (cell==nil)
          {
              cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
      
          }
          cell.textLabel.text=[ExpArr objectAtIndex:indexPath.row];
          cell.textLabel.backgroundColor=[UIColor clearColor];
          UIView *viewww=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
          viewww.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.png"]];
          cell.backgroundView=viewww;
      
         // cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.png"]];
          [tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];
          [tableView setSeparatorColor:[UIColor purpleColor]];
      
          return cell;
      
      }
      
      -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
      {
      
          UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
          [view1.layer setCornerRadius:20];
          view1.layer.borderWidth=2;
          view1.layer.borderColor=[UIColor brownColor].CGColor;
          UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, 295, 44)];
          label.backgroundColor=[UIColor clearColor];
      
          label.text=[muArr objectAtIndex:section];
          UIButton *btn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
          btn.frame=CGRectMake(280, -5, 50, 50);
          btn.backgroundColor=[UIColor clearColor];
          btn.tag=section;
      
          view1.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.png"]];
          label.textColor=[UIColor blackColor];
          label.font=[UIFont fontWithName:@"American TypeWriter" size:18];
          //btn.backgroundColor=[UIColor blackColor];
          [view1 addSubview:btn];
          [view1 addSubview:label];
      
          [btn addTarget:self action:@selector(Btntap:) forControlEvents:UIControlEventTouchUpInside];
      
          return view1;
      }
      
      
      -(void)Btntap : (UIButton *)btn
      {
          if(otherExpand!=100)
          {
              if (otherExpand==btn.tag)
              {
                  NSMutableArray *tempArr2=[[NSMutableArray alloc]init];
                  for(int j=0;j<ExpArr.count;j++)
                  {
                      NSIndexPath *indexx1=[NSIndexPath indexPathForRow:j inSection:otherExpand];
                      [tempArr2 addObject:indexx1];
                  }
                  checker=0;
                  otherExpand=100;
                  [myTable deleteRowsAtIndexPaths:tempArr2 withRowAnimation:UITableViewRowAnimationAutomatic];
              }
      
              else
              {
                  NSMutableArray *tempArr2=[[NSMutableArray alloc]init];
                  for(int j=0;j<ExpArr.count;j++)
                  {
                      NSIndexPath *indexx1=[NSIndexPath indexPathForRow:j inSection:otherExpand];
                      [tempArr2 addObject:indexx1];
                  }
                  checker=1;
                  otherExpand=100;
                  [myTable deleteRowsAtIndexPaths:tempArr2 withRowAnimation:UITableViewRowAnimationAutomatic];
              }
          }
      
          if(checker!=0)
          {
              otherExpand=btn.tag;
              //checker=
              NSMutableArray *tempArr=[[NSMutableArray alloc]init];
              for(int i=0;i<ExpArr.count;i++)
              {
                  NSIndexPath *indexx=[NSIndexPath indexPathForRow:i inSection:btn.tag];
                  [tempArr addObject:indexx];
              }
              [myTable insertRowsAtIndexPaths:tempArr withRowAnimation:UITableViewRowAnimationAutomatic];
      
              checker=1;
          }
          checker=100;
      }
      
      
      
      -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
      {
          return 44;
      }
      
      @end
      

      【讨论】:

      • 我试过了,但没有得到我想要的东西,因为我的字典是动态的
      • @VinayKumar 我复制粘贴了代码,但它没有扩展你能帮我写代码吗?
      • @Vinay Kumar .. 如果我想在每个部分添加不同的行意味着我该如何修改。假设如果section1=4,section2=6。
      • @UmaMadhavi 这是我很久以前使用的代码之一。创建带有部分的展开-折叠单元格的更好方法是在部分标题中放置一个按钮。当按下该按钮时,您必须在该特定部分中插入行(带动画)。
      • @VinayKumar .. 很长一段时间后,我不得不使用扩展表视图。我想扩展部分或行。我怎样才能做到这一点,请你指导我。
      【解决方案6】:

      WWDC 2011 中有一个很棒的视频,名为 UITableView Changes, Tips and Tricks - session 125,它展示了如何做这样的事情。
      另请查看示例代码TVAnimationsGestures

      【讨论】:

        【解决方案7】:

        您可以在 Swift 中查看这个手风琴示例:https://github.com/tadija/AEAccordion

        创建手风琴效果的代码很少(不是通过使用部分,而是通过单元格),作为奖励,还有一个解决方案可以在其他 XIB 文件中使用 XIB 文件(对于使用自定义视图的自定义单元格很有用)。

        【讨论】:

          【解决方案8】:

          请试试这个例子:

          Expandable TableView 的最佳示例

          https://github.com/OliverLetterer/UIExpandableTableView

          【讨论】:

            【解决方案9】:

            TLIndexPathTools 可以自然地做这种事情。事实上,可扩展部分和可扩展树结构都有扩展。尝试为可扩展部分运行 Collapse 示例项目,为可扩展树运行 Outline sample project

            使用 TLIndexPathTools 的一个优点是,作为一个简单的低级 API,它可以使用通用方法解决各种动态表视图和集合视图问题。它可以与 Core Data 和普通数组互换使用。

            【讨论】:

              【解决方案10】:

              创建可扩展的 tableview 非常容易 这是我如何做到这一点的一个例子,

              我用于这个的数据

              struct ItemList {
              var name: String
              var items: [String]
              var collapsed: Bool
              
              init(name: String, items: [String], collapsed: Bool = false) {
                 self.name = name
                 self.items = items
                 self.collapsed = collapsed
                 }
              }
              
              var sections = [ItemList]()
              
              var items: [ItemList] = [
               ItemList(name: "Mac", items: ["MacBook", "MacBook Air"]),
               ItemList(name: "iPad", items: ["iPad Pro", "iPad Air 2"]),
               ItemList(name: "iPhone", items: ["iPhone 7", "iPhone 6"])
              ]
              

              现在只需添加这段代码并相应地使用

              extension ViewController:UITableViewDelegate,UITableViewDataSource{
              
              func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
                  return 60
              }
              
              func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
                  let headerHeading = UILabel(frame: CGRect(x: 5, y: 10, width: self.view.frame.width, height: 40))
                  let imageView = UIImageView(frame: CGRect(x: self.view.frame.width - 30, y: 20, width: 20, height: 20))
                  if items[section].collapsed{
                      imageView.image = UIImage(named: "collapsed")
                  }else{
                      imageView.image = UIImage(named: "expand")
                  }
                  let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 60))
                  let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(headerViewTapped))
                  tapGuesture.numberOfTapsRequired = 1
                  headerView.addGestureRecognizer(tapGuesture)
                  headerView.backgroundColor = UIColor.red
                  headerView.tag = section
                  headerHeading.text = items[section].name
                  headerHeading.textColor = .white
                  headerView.addSubview(headerHeading)
                  headerView.addSubview(imageView)
                  return headerView
               }
              func numberOfSections(in tableView: UITableView) -> Int {
                  return items.count
              }
              func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                  let itms = items[section]
                  return !itms.collapsed ? 0 : itms.items.count
              }
              
              func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                  let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! UITableViewCell
                  cell.textLabel?.text = items[indexPath.section].items[indexPath.row]
                  return cell
              }
              @objc func headerViewTapped(tapped:UITapGestureRecognizer){
                  print(tapped.view?.tag)
                  if items[tapped.view!.tag].collapsed == true{
                      items[tapped.view!.tag].collapsed = false
                  }else{
                      items[tapped.view!.tag].collapsed = true
                  }
                  if let imView = tapped.view?.subviews[1] as? UIImageView{
                      if imView.isKind(of: UIImageView.self){
                          if items[tapped.view!.tag].collapsed{
                              imView.image = UIImage(named: "collapsed")
                          }else{
                              imView.image = UIImage(named: "expand")
                          }
                      }
                  }
                  tableView.reloadData()
              }
              
              }
              

              结果是宾果游戏:)

              【讨论】:

              • 如何在 Index 方法中使用 DidSelectRow ?
              【解决方案11】:

              我需要将单个单元格扩展为更完整的视图并将其折叠回摘要视图。

              所以我所做的是使用UIStackView 设计我的单元格。我将我不想在折叠状态下显示的视图隐藏起来,然后在点击单元格时显示它。

              这里的技巧是在tableView.beginUpdates()tableView.endUpdates() 语句中显示和隐藏视图。通过这种方式,表格视图会自动调整单元格高度并以动画方式进行调整。

              下面是基本单元格在 IB 中的外观:

              单元格自定义类:

                  class AccordionCell: UITableViewCell {
                  @IBOutlet weak var stackView: UIStackView!
                  
                  @IBOutlet weak var titleLabel: UILabel!
                  @IBOutlet weak var descriptionLabel: UILabel!
                  @IBOutlet weak var extendedDescriptionLabel: UILabel!
              
                  var expanded: Bool = false {
                      didSet {
                          if let extended = self.extendedDescriptionLabel {
                              extended.isHidden = !expanded
                          }
                      }
                  }
                  
                  override func awakeFromNib() {
                      super.awakeFromNib()
                      // Initialization code
                      self.expanded = false
                  }
              
                  override func setSelected(_ selected: Bool, animated: Bool) {
                      super.setSelected(selected, animated: animated)
              
                      // Configure the view for the selected state
                  }    
              }
              

              UITableView 委托实现:

              extension ViewController: UITableViewDataSource, UITableViewDelegate {
                  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                      return 100
                  }
                  
                  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                      let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier) as! AccordionCell
                      cell.titleLabel.text = "Row: \(indexPath.row)"
                      cell.expanded = indexPath.row == expanded
                      return cell
                  }
                  
                  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                      if let cell = tableView.cellForRow(at: indexPath) as? AccordionCell {
                          tableView.beginUpdates()
                          if expanded == indexPath.row {
                              cell.expanded = false
                              expanded = -1
                          }
                          else {
                              cell.expanded = true
                              expanded = indexPath.row
                          }
                          
                          tableView.endUpdates()
                          tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
                      }
                  }
                  
                  func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
                      if let cell = tableView.cellForRow(at: indexPath) as? AccordionCell {
                          tableView.beginUpdates()
                          cell.expanded = false
                          tableView.endUpdates()
                      }
                  }
              }
              

              为了跟踪哪个单元格展开了,我引入了一个变量保存当前展开单元格的indexpath,以便在滚动表格视图时展开右侧单元格。

              【讨论】:

                【解决方案12】:

                检查此链接:

                http://iostechnotips.blogspot.in/2014/05/expandable-uitableview.html

                -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
                

                *使用UITableView委托方法viewForHeaderInSection并返回一个自定义的UIView。

                *添加UIButton 作为子视图,操作为“expandable:(id)sender”,检查发件人 ID 作为部分编号并重新加载表格视图。

                【讨论】:

                  【解决方案13】:

                  在你的 .h 文件中

                  LoadCustomCell *cell1;
                  NSMutableArray  *arrayForBool;
                  NSMutableArray  *questionArray;
                  NSMutableArray  *answerArray;
                  

                  在您的 .m 文件中

                   viewDidLoadMethod {
                   _faqTblView.estimatedRowHeight = 30;
                   _faqTblView.rowHeight = UITableViewAutomaticDimension;
                   arrayForBool = [[NSMutableArray alloc]init];
                  
                   _questionArray = [[NSMutableArray alloc]init];
                   _answerArray = [[NSMutableArray alloc]init];
                   for (int i = 0; i < _questionArray.count; i++) {
                          [arrayForBool addObject:@"0"];
                      }
                      self.faqTblView.dataSource = self;
                      self.faqTblView .delegate = self;
                      [self.faqTblView reloadData];
                   }
                  

                  之后

                   #pragma mark - TableView Datasource & Delegate Method.
                  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
                    return [_questionArray count];
                   }
                  - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
                  
                      UILabel *lblText = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 260, 100)];
                      lblText.text = [_questionArray objectAtIndex:section];
                      return [lblText getLabelHeight] + 20;(created custom class)
                   }
                  -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
                  
                  UITapGestureRecognizer  *headerTapped   = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)];
                  cell1 = [[[NSBundle mainBundle] loadNibNamed:@"LoadCustomCell" owner:self options:nil] objectAtIndex:0];
                  [cell1 setFrame:CGRectMake(0, 0, cell1.frame.size.width, cell1.frame.size.height)];
                  NSString *numStr = [NSString stringWithFormat:@"%ld. ",section + 1];
                  [cell1.sideMenuUserNameLabel setText:[numStr stringByAppendingString:[_questionArray objectAtIndex:section]]];
                  [cell1 setBackgroundColor:[UIColor lightGrayColor]];
                  cell1.tag = section;
                  [cell1 addGestureRecognizer:headerTapped];
                  
                  return cell1;
                  }
                  
                  - (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer {
                  
                  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag];
                  if (indexPath.row == 0) {
                      BOOL collapsed  = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
                      for (int i = 0; i < [_questionArray count]; i++) {
                          if (indexPath.section==i) {
                              [arrayForBool removeObjectAtIndex:i];
                              [arrayForBool insertObject:[NSString stringWithFormat:@"%d", !collapsed] atIndex:i];
                          }
                      }
                      NSLog(@"%@", arrayForBool);
                      [self.faqTblView reloadSections:[NSIndexSet indexSetWithIndex:gestureRecognizer.view.tag] withRowAnimation:UITableViewRowAnimationAutomatic];
                      for (NSIndexPath *indexPath in self.faqTblView.indexPathsForSelectedRows) {
                          [self.faqTblView deselectRowAtIndexPath:indexPath animated:NO];
                           }
                      cell1.imageView.transform = CGAffineTransformMakeRotation(M_PI);
                       }
                  }
                  
                  -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
                  static NSString *questionCellIdentifier = @"questionCellIdentifier";
                  QuestionCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:questionCellIdentifier];
                  if (cell == nil) {
                      NSArray * myNib;
                      myNib =[[NSBundle mainBundle]loadNibNamed:@"QuestionCustomCell" owner:self options:nil];
                      cell = (QuestionCustomCell *)[myNib lastObject];
                  }
                  
                  BOOL manyCells  = [[arrayForBool objectAtIndex:indexPath.section] boolValue];
                  if(manyCells){
                      cell.questionNameLbl.text = [_answerArray objectAtIndex:indexPath.section];
                  }
                  return cell;
                  }
                  

                  【讨论】:

                    【解决方案14】:

                    你可以使用ExpyTableView

                    这会从您的给定单元格中生成一个可展开的部分。兼容至 iOS 8.0。通过生成具有多个表格视图单元格的可扩展表格视图,您将获得灵活性。只需操作状态的分隔符,然后没人会知道您使用多个单元格进行扩展。

                    • 其他解决方案:您操纵高度来扩展单元格,当单元格设计需要更新时,您必须重新构建所有自动布局约束或逻辑代码。

                    • ExpyTableView:您通过使用多个单元格并插入和删除它们(这可能意味着展开和折叠)来制作可展开的表格视图,您将有很大的机会在未来的设计请求中。您所要做的就是添加一个新的 UITableViewCell 并为其编写代码。您将轻松拥有新设计。

                    你所要做的就是import ExpyTableView然后:

                    class ViewController: ExpyTableViewDataSource, ExpyTableViewDelegate {
                    
                      @IBOutlet weak var expandableTableView: ExpyTableView!
                    
                      // First, set data source and delegate for your table view.
                      override func viewDidLoad() {
                        super.viewDidLoad() 
                        expandableTableView.dataSource = self
                        expandableTableView.delegate = self
                      }
                    
                      // Then return your expandable cell instance from expandingCell data source method.
                      func expandableCell(forSection section: Int, inTableView tableView: ExpyTableView) -> UITableViewCell {
                        // this cell will be displayed at IndexPath with section: section and row 0
                      }
                    } 
                    

                    您可以看到以前的表格视图部分现在是可展开的表格视图部分。您也可以下载example project 并查看更详细的示例。

                    【讨论】:

                      【解决方案15】:

                      UITableView with Collapsible (expand and collapse) Cells swift 5

                      • 自定义单元格非常易于使用

                      • 消耗品

                      • 动态内容

                      查看 Github 链接: https://github.com/Murteza12/ExpandableTablew/wiki/UITableView-with-Collapsible-(expand-and-collapse)-Cells

                      【讨论】:

                        猜你喜欢
                        • 2017-11-10
                        • 1970-01-01
                        • 2020-04-04
                        • 2017-12-04
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        相关资源
                        最近更新 更多