I'm trying to display a "that's all" message to the user if the user reaches the bottom of the table view but keeps scrolling up, like the "you're up to date" message slack displays at the bottom of the chat. However, the tableFooterView
can be seen at the very bottom of the table view and isn't hidden. How should this be done?
Asked
Active
Viewed 1,544 times
0

Pirlo Lochisomo
- 185
- 1
- 16
-
are u using `TableViewData` source to add footerView ?? – Dhiru Mar 06 '17 at 14:44
-
@Dhiru I simply set a UILabel for `self.tableView.tableFooterView` – Pirlo Lochisomo Mar 06 '17 at 14:46
3 Answers
1
I use this solution:
let test=UILabel(frame: CGRect(x: 0,y: tableView.contentSize.height+180, width: tableView.frame.width, height: 50))
test.text="That's all"
view.insertSubview(test, belowSubview: tableView)

omarzl
- 589
- 4
- 9
-
Where did you put this code? I put it in cellForRowAtIndexPath but I still cannot see the label at the bottom of the table view – Pirlo Lochisomo Mar 07 '17 at 01:56
-
-
-
Well, after you reload your tableview. If you populate the tableview async you should update the position of the label after you reload the table view. – omarzl Mar 07 '17 at 16:16
0
Adding a footerview won't work because then the tableview will adjust its contentSize to display it.
You can add a subview directly to the UITableView, set its frame's origin.y to be greater than the contextSize.y. Whenever you add or remove rows, or add or remove section section or reload the table you have to readjust the view.

Jon Rose
- 8,373
- 1
- 30
- 36
0
I faced the same problem and the above solution did not work for me.
I ended up using auto layout constraints. Initially the footer view's bottom anchor is set a bigger constrant to keep it invisible
Then used begin & end dragging methods of scroll view delegate to show & hide it
extension ViewController: UITableViewDelegate {
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
guard let bottomAnchor = self.bottomAnchor else { return }
guard scrollView.contentSize.height > scrollView.frame.size.height else { return }
let heightOfInvisibleContent = (scrollView.contentSize.height - scrollView.frame.size.height)
print("height of invisible content: \(heightOfInvisibleContent), offset: \(scrollView.contentOffset.y)")
guard scrollView.contentOffset.y >= heightOfInvisibleContent else { return }
bottomAnchor.constant = moveUpConstant
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
guard let bottomAnchor = self.bottomAnchor else { return }
bottomAnchor.constant = moveDownConstant
UIView.animate(withDuration: 0.5) {
self.view.layoutIfNeeded()
}
}
}
I have shared my full sample project (FooterMessage) in my repo https://github.com/ramjyroo/iOS-Expedition

ram
- 78
- 1
- 8