国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 永昌县| 台南市| 南康市| 小金县| 江山市| 北京市| 博爱县| 会同县| 新河县| 榆树市| 玉环县| 萝北县| 交口县| 桃江县| 济南市| 九江县| 仪征市| 澄城县| 浠水县| 晋中市| 永仁县| 乳源| 修水县| 浪卡子县| 苍南县| 宁阳县| 莱州市| 宁南县| 米泉市| 汽车| 南皮县| 科技| 自治县| 景洪市| 平和县| 宜君县| 灵台县| 安阳市| 唐山市| 荣成市| 潜山县|