如何实现iOS中细胞的部分展开和收起

  介绍

小编给大家分享一下如何实现iOS中细胞的部分展开和收起,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

首先,先上图,让大家看看效果

, 如何实现iOS中细胞的部分展开和收起

相信大家对于TableViewd数据的设置都熟悉,这方面就不多说的,重点的还是来看:

<强> 1。如何实现细胞的部分的展开和收起的效果

安康;(void) tableView: (UITableView  *) tableView  didSelectRowAtIndexPath: (NSIndexPath  *) indexPath  {   (才能self.tableView  deselectRowAtIndexPath: indexPath 动画:没有);         时间=currentRow 才能;indexpath。row;      NSDictionary 才能;* sectionDic =, self.dataSource [indexPath.section];   NSArray 才能;* cellArray =, sectionDic [@" sub"];//细胞才能当前的数据   NSDictionary 才能;* cellData =, cellArray (indexpath。row);      NSString 才能;* key =, (NSString  stringWithFormat: @" % @",, cellData [@" chapterID"]];   CellModel 才能;* chapterModel =, (self.cellOpen  valueForKey:关键);      chapterModel.isShow 才能=,! chapterModel.isShow;      (才能self.tableView  reloadRowsAtIndexPaths: @ [indexPath], withRowAnimation: UITableViewRowAnimationAutomatic);   }

当用户点击到某一个单元格时候,需要判断细胞是否是展开状态,如果张开或者收起就调用

代码如下:


[自我。tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];

让细胞的部分能够重新加载刷新;

<强> 2。如何添加细胞的部分

<强> 2.1设置部分的高度

安康;(CGFloat) tableView: (UITableView  *) tableView  heightForRowAtIndexPath: (NSIndexPath  *) indexPath  {   NSDictionary 才能;* sectionDic =, self.dataSource [indexPath.section];   NSArray 才能;* cellArray =, sectionDic [@" sub"];//细胞才能当前的数据   NSDictionary 才能;* cellData =, cellArray (indexpath。row);      NSString 才能;* key =, (NSString  stringWithFormat: @" % @",, cellData [@" chapterID"]];   CellModel 才能;* model =, (self.cellOpen  valueForKey:关键);   if 才能;(model.isShow), {   ,,,return  (model.pois.count + 1) * 60;   ,,},{else    ,,,return  60;   ,,}      }

上面的代码是设置部分的高度,主要是以细胞的isshow作为标记,让部分的能够随数据的改变而变动

<强> 3。如果要在一个细胞上再加一个细胞,实现细胞内嵌细胞,需要在哪里加?

答案:当然是在细胞的HeaderSection或者FooterSection上加上细胞,这样就能实现细胞内嵌细胞。

看完了这篇文章,相信你对“如何实现iOS中细胞的部分展开和收起”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

如何实现iOS中细胞的部分展开和收起