欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何實(shí)現(xiàn)iOS中Cell的Section展開和收起

小編給大家分享一下如何實(shí)現(xiàn)iOS中Cell的Section展開和收起,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

成都創(chuàng)新互聯(lián)主營興國網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app軟件開發(fā)公司,興國h5小程序設(shè)計(jì)搭建,興國網(wǎng)站營銷推廣歡迎興國等地區(qū)企業(yè)咨詢

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

 如何實(shí)現(xiàn)iOS中Cell的Section展開和收起

相信大家對(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。

看完了這篇文章,相信你對(duì)“如何實(shí)現(xiàn)iOS中Cell的Section展開和收起”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前標(biāo)題:如何實(shí)現(xiàn)iOS中Cell的Section展開和收起
當(dāng)前路徑:http://chinadenli.net/article46/giojhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站營銷、微信公眾號(hào)、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化