国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS中Cell的Section展開和收起的示例代碼

2019-10-21 18:45:00
字體:
供稿:網(wǎng)友

整理文檔,搜刮出一個(gè)ios/197892.html">ios/252451.html">iOS中Cell的Section展開和收起的示例代碼,稍微整理精簡一下做下分享。

首先,先上圖,讓大家看看效果

 iOS,Section展開和收起,收起和展開,Cell收起和展開

相信大家對(duì)于TableViewd數(shù)據(jù)的設(shè)置都熟悉,這方面就不多說的,重點(diǎn)的還是來看:

1.如何實(shí)現(xiàn)cell的Section的展開和收起的效果

- (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當(dāng)前的數(shù)據(jù)  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];}

當(dāng)用戶點(diǎn)擊到某一個(gè)cell時(shí)候,需要判斷cell是否是展開狀態(tài),如果張開或者收起就調(diào)用

 

復(fù)制代碼 代碼如下:

[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

 

讓cell的section能夠重新加載刷新;

2.如何添加cell的Section

2.1設(shè)置section的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  NSDictionary *sectionDic = self.dataSource[indexPath.section];  NSArray *cellArray = sectionDic[@"sub"];  //cell當(dāng)前的數(shù)據(jù)  NSDictionary *cellData = cellArray[indexPath.row];  NSString *key = [NSString stringWithFormat:@"%@", cellData[@"chapterID"]];  CellModel *model = [self.cellOpen valueForKey:key];  if (model.isShow) {    return (model.pois.count+1)*60;  } else {    return 60;  }}

上面的代碼是設(shè)置section的高度,主要是以cell的isshow作為標(biāo)記,讓section的能夠隨數(shù)據(jù)的改變而變動(dòng)

3.如果要在一個(gè)cell上再加一個(gè)cell,實(shí)現(xiàn)cell內(nèi)嵌cell,需要在哪里加?

答案:當(dāng)然是在cell的HeaderSection或者FooterSection上加上cell,這樣就能實(shí)現(xiàn)cell內(nèi)嵌cell。

好了,說了那么多,估計(jì)大家還是喜歡看demo,以下是demo的鏈接:https://github.com/xiaojin1123/SectionOpenAndClose.git

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洮南市| 新安县| 西城区| 丰县| 巴塘县| 宁武县| 蚌埠市| 邵东县| 濮阳县| 同德县| 东宁县| 新沂市| 庆元县| 长兴县| 长汀县| 东光县| 芦溪县| 贵州省| 宁海县| 河间市| 利辛县| 宕昌县| 泸州市| 杭锦后旗| 平山县| 枣阳市| 宜川县| 永年县| 唐海县| 任丘市| 紫阳县| 二手房| 偏关县| 芦溪县| 台北市| 炉霍县| 临猗县| 巩义市| 黔江区| 西吉县| 台中市|