• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 有没有办法隐藏 UITableView 的页脚?

[复制链接]
菜鸟教程小白 发表于 2022-12-11 20:35:48 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个 View Controller 内部的表格 View ,表格 View 根据动态单元格调整大小,有时只有 1 行,有时更多,问题是表格 View 的页脚占用了大量空间,我想要要隐藏的页脚,我尝试使用委托(delegate)方法 viewForFooterInSection,并在 viewdidload 方法中将页脚高度设置为 0,在 heightForFooterInSection 中设置为 1.0,页脚仍在显示,这是 tableview 的照片,我制作了页脚背景黑色以检查它在哪里

enter image description here 这是我在 viewdidload 中使用的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    let notificationName = Notification.Name(rawValue: "ErrorGettingReportDetail")
    NotificationCenter.default.addObserver(self, selector: #selector(self.mostrarErrorDetalle), name: notificationName, object: nil)
    // Do any additional setup after loading the view.
    /*self.backView.layer.cornerRadius = 10
    self.backView.layer.masksToBounds = true*/

    self.backScrollView.layer.cornerRadius = 10
    self.backScrollView.layer.masksToBounds = true

    self.commentTextView.delegate = self
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissCommentsPopUp")
    view.addGestureRecognizer(tap)

    self.tagsTableView.dataSource = self
    self.commentTextView.autocorrectionType = .no

    self.tagsTableView.estimatedRowHeight = 40
    self.tagsTableView.rowHeight = UITableViewAutomaticDimension
}

这是我用于表格 View 的代码:

//MARK: -TagsTableView
func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if(self.reporte != nil){
        if((self.reporte?.atributosInfo?.count)! > 0){
            return (self.reporte?.atributosInfo?.count)!
        }else{
            //self.tagsTableView.isHidden = true
            return 0
        }
    }else{
        return 0
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if(KRProgressHUD.isVisible){
        KRProgressHUD.dismiss()
    }
    if(self.reporte != nil){
        let cell = tableView.dequeueReusableCell(withIdentifier: "atributoCell") as! AtributoTableViewCell
        let atributosInfo = self.reporte?.atributosInfo![indexPath.row]
        cell.configureCellWith(atributoInfo: atributosInfo!)
        cell.atributo = atributosInfo
        print(indexPath.row)
        let height = cell.frame.height
        self.tagsTableViewHeight.constant += height
        return cell
    }else{
        let cell = UITableViewCell()
        //self.tagsTableViewHeight.constant -= cell.frame.height
        return cell
    }
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 100
}

//MARK END

我们将不胜感激。



Best Answer-推荐答案


请用这个

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNonzeroMagnitude
}

关于ios - 有没有办法隐藏 UITableView 的页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52340566/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap