源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

iOS中Cell的Section展开和收起的示例代码

  • 时间:2021-08-18 04:30 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS中Cell的Section展开和收起的示例代码
整理文档,搜刮出一个iOS中Cell的Section展开和收起的示例代码,稍微整理精简一下做下分享。 首先,先上图,让大家看看效果  [img]http://files.jb51.net/file_images/article/201708/2017821110355165.png?201772111411[/img] 相信大家对于TableViewd数据的设置都熟悉,这方面就不多说的,重点的还是来看: [b]1.如何实现cell的Section的展开和收起的效果[/b]
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  [self.tableView deselectRowAtIndexPath:indexPath animated:NO];


  currentRow = indexPath.row;

  NSDictionary *sectionDic = self.dataSource[indexPath.section];
  NSArray *cellArray = sectionDic[@"sub"];

  //cell当前的数据
  NSDictionary *cellData = cellArray[indexPath.row];

  NSString *key = [NSString stringWithFormat:@"%@", cellData[@"chapterID"]];
  CellModel *chapterModel = [self.cellOpen valueForKey:key];

  chapterModel.isShow = !chapterModel.isShow;

  [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
当用户点击到某一个cell时候,需要判断cell是否是展开状态,如果张开或者收起就调用
[url=https://github.com/xiaojin1123/SectionOpenAndClose.git]https://github.com/xiaojin1123/SectionOpenAndClose.git[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部