Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tableview footer not show

Tags:

ios

swift

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.

like image 571
ankmara Avatar asked Mar 12 '23 00:03

ankmara


2 Answers

You forgot 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
}
like image 54
guidev Avatar answered Mar 15 '23 14:03

guidev


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

    let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
    footerView.addSubview(activityIndicator)
    return footerView
}
like image 23
Subin K Kuriakose Avatar answered Mar 15 '23 15:03

Subin K Kuriakose