IOS 开发使用UIStoryBoard时如何隐藏UITableViewController中的Section

本文介绍如何在Swift中通过调整TableView的section数量、高度及cell数量来实现动态隐藏特定Section的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在StoryBoard直接删除当然简单啦,可是在业务要求动态显示时,就不一样了,当然,如果没用StoryBoard也好控制,可是偏偏当初做的时间用了StroryBoard

好说,就在这几个方法上动工就行了:


//控制section的个数,如果你要隐藏的 section在末尾,用它就行了

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

  return 6

 } 


//要隐藏的section,就用用这两个方法,让们的高度为0.1

 override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

  if(section == 3 ){ 

  return 0.1

 } 

  return super.tableView(tableView, heightForHeaderInSection: section) 

 }


 override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {

  if(section == 3  ){

  return 0.1

  }

  return super.tableView(tableView, heightForFooterInSection: section) 

 }


//另外,控投制section中cell的个数,用这个方法

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

if(section == 3  ){

  return 0

}

  return 1 

 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值