user843337
user843337

Reputation:

Why does UITableView footer appear over the top of the last cell?

I have a UITableView which contains a bunch of cells (dynamically generated) and it displays a footer message showing the last updated time. The issue I'm having is that on the first loading of the UITableView it seems to display the footer over the top of the last cell. Once you reload the data it displays it correctly though.

Does anybody know why this is happening?

Initial loading:

enter image description here

After reloading:

enter image description here

The following is the logic I use for establishing the footer message to display:

override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? {

    var title = ""
    if (section == kSectionA) {
        if (!self.hasInternet) {
            title = "No Internet Connection"
        } else {
            if (self.dataToDisplay) {
                title = "Last Updated: xx:xx AM"
            } else {
                title = "No results found."
            }
        }
    }

    return title
}

Upvotes: 1

Views: 2092

Answers (1)

Mr UziBazooka
Mr UziBazooka

Reputation: 222

You need to tell the Tableview how big the footer is from the beginning.Try using this code but with your values.

Tells the Tableview how big the footer is:

override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))
footerView.backgroundColor = UIColor.grayColor()

return footerView
}

Tells the footer how big the footer is:

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

That should solve you problem.

Upvotes: 2

Related Questions