OGeek|极客世界-中国程序员成长平台

标题: ios - 有没有办法隐藏 UITableView 的页脚? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:35
标题: ios - 有没有办法隐藏 UITableView 的页脚?

我有一个 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4