任何人都可以告诉如何实现可展开/折叠表视图



这是我在下面附加的屏幕和代码。任何人都可以提前给出如何实现屏幕的想法吗?在我的标题部分中,我只需要显示表格视图单元格......

   [1]: https://i.stack.imgur.com/EVlQs.png
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section
{
return [arr count];
}

-(UITableViewCell*)tableView:(UITableView *)tableView    cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellidentifier =@"cell";
MyOrderCell *cell = (MyOrderCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];

/********** If the section supposed to be closed *******************/
if(cell==nil)
{
    cell = [[MyOrderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
if (selectedindex==indexPath.row) {
    // do expanded stuff here
    cell.lblcope.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"pendents"];
    cell.lblcopieces.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"copiece"];
    cell.lblconum.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"conum"];
    cell.lblcodate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"codate"];
    cell.lblcoenddate.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"coenddate"];
    cell.lbltotl.text=[[pendentsdata objectAtIndex:indexPath.row]valueForKey:@"cototal"];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}else
{
    // do closed stuff here
    cell.lblpendnts.text=[arr objectAtIndex:indexPath.row];
    cell.lblpieces.text=[arrpieces objectAtIndex:indexPath.row];
    cell.lblnum.text=[arrnum objectAtIndex:indexPath.row];
    cell.lbldate.text=[arrdate objectAtIndex:indexPath.row];
    cell.lblenddate.text=[arrenddate objectAtIndex:indexPath.row];
    cell.lbltotl.text=[arrttl objectAtIndex:indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedindex==indexPath.row) {
    selectedindex=-1;
    [tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    return;
}
if (selectedindex !=-1) {
    NSIndexPath *prevpath=[NSIndexPath indexPathForRow:selectedindex inSection:0];
    selectedindex=indexPath.row;
    [tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevpath] withRowAnimation:UITableViewRowAnimationFade];
   }
    selectedindex=indexPath.row;
   [tbldata reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   }
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
   {
if (selectedindex==indexPath.row) {
    return 100;
   }else
   {
    return 50;
   }
  }

您可以使用 https://github.com/iSofTom/STCollapseTableView

我已经在一个项目中使用了它。编写的代码非常干净,因此您还可以轻松自定义它以满足您的特定需求(如果有的话)。

您可以使用

SubTable,这是UITableView的第三方子类。除了下面与您的相同问题外,请查看它们:

如何在UItableview

下创建带有UItableview的手风琴?

手风琴表单元格 - 用于展开和折叠 ios

确实是

布拉克,或者参加教程...示例:https://blog.pivotal.io/labs/labs/expandable-uitableviewcells

最新更新