Home > Blockchain >  Change tableView heightForFooterInSection depending on iOS version
Change tableView heightForFooterInSection depending on iOS version

Time:01-05

I have noticed that the last row of my tableView is being cut off on the older iOS versions(<15.0).
I decided to change the tableView footer depending on iOS version, so I want to hold the default footer if version is >= 15.0, but dont know how.
Here is the code:

    override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if #available(iOS 15.0, *) {
            //Problem is here. I must return something.
        } else {
            return 75 //This is ok
        }
    }

I have tried to return

  • UIView().frame.size.height
  • UITableView.automaticDimension

but it even makes more problems(returns 0).
Is there any other way to return the default footer on new iOS versions?

CodePudding user response:

The above code must be give you the default height

return myTableView.sectionFooterHeight

But , If you use footer view only for making some space to bottom side of the view , you dont need to add footer to your tableview , you can give some space to contentInset's bottom , this gonna fix the cut on last cell.

On viewdidload

    if #available(iOS 15.0, *) {
        // do nothing
    } else {
       self.myTableView.contentInset.bottom = 75

    }
  •  Tags:  
  • Related