8
tableView.setContentOffset(CGPointMake(0, tableView.contentSize.height - tableView.frame.size.height), animated: true)

It works, but I wonder what actually are those two values: tableView.contentSize, tableView.frame.size

Honey
  • 24,125
  • 14
  • 123
  • 212
Bartłomiej Semańczyk
  • 52,820
  • 43
  • 206
  • 318
  • It's related to the `UIScrollView` part, about what's actually shown and what's the whole size in reality (counting the "hidden" content, not shown except if you scroll) – Larme Jan 29 '15 at 10:15
  • 2
    if you wanna go deep, take a look on [this](http://www.objc.io/issue-3/scroll-view.html) – Ethaan Jan 29 '15 at 10:17

1 Answers1

18

The contentSize is the size of the content of the UIScrollView, that means it will be the size of the content (hidden and visible) whereas the frame.size is the real size of your tableView.

For example, let's say I have a device's screen of 568 (height), and inside it, I have an UITableView (taking all the screen) with 100 cells and an height of 50 for each of them. My tableView.frame.size.height will be equal to 568, but the tableView.contentSize.height will be equal of the scroll's size of all the cells, so 5000.

Also, as suggested by @Ethaan, read this to go deeper.

tbaranes
  • 3,420
  • 1
  • 20
  • 31