首页 > 解决方案 > 有没有办法隐藏 UITableView 的页脚?

问题描述

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

在此处输入图像描述 这是我在 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
}

这是我用于表格视图的代码:

//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

任何帮助将不胜感激。

标签: iosswiftuitableviewswift4

解决方案


请使用这个

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

推荐阅读