ankmara ankmara - 5 months ago 27
Swift Question

Tableview footer not show

Iam trying to add tableview to view controller. Everything is ok, but footer is hidden/disable? I don't know.

My code:

private let footerView = UIView()
footerView.backgroundColor = UIColor.Green.color
footerView.addSubview(activityIndicator)
tableView.addSubview(footerView)

tableView.delegate = self
tableView.dataSource = self
tableView.tableFooterView = footerView
tableView.sectionFooterHeight = 20
tableView.footerViewForSection(0)
tableView.tableHeaderView = footerView


for sure:

func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "test.."
}

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return footerView
}

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


I tried both implementation separate and nothing (white space only).

And my footer view is light gray and implemented activity indicator is "invisible" (frame is set up)

Its ViewController with tableView.

Any idea, why isn't footer view visible right?

Thank you.

Answer

You forget to set the frame of your footerView


Remove all the first part of your code and use this:

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    return UIView(frame: CGRectMake(0, 0, tableView.bounds.size.width, 20))
}

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 20
}
Comments