Long story short, iOS8 has a bug with UITableViewAutomaticDimension
So, you can't just call your tableView.rowHeight = UITableViewAutomaticDimension
followed by the estimatedRowHeight because when reloading data someway through, you end up getting very jumpy, weird looking scrolling.
The way to mitigate this is apparently to return what the height of the cell is in func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
Since you can't call cellForRowatIndexPath:
in heightForRowAtIndexPath:
, I basically copied my cellForRowAtIndexPath
into the other method and changed it up for height. I can't seem to get it working though because my UILabel (the one with dynamic height in the cell), conforms to one line and just truncates instead of going on for x lines until all the content is displayed.
Note, postBody
is the text that has a dynamic height.
My cellForRowAtIndexPath:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = self.feed.dequeueReusableCellWithIdentifier("post") as UITableViewCell
var userName = cell.viewWithTag(1)! as UILabel
var timestamp = cell.viewWithTag(2)! as UILabel
var postBody = cell.viewWithTag(5)! as UILabel
var post = self.posts[indexPath.row]
userName.text = post.name
timestamp.text = post.timestamp
postBody.text = post.body
return cell
}
my heightForRowAtIndexPath:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
var cell: UITableViewCell = self.feed.dequeueReusableCellWithIdentifier("post") as UITableViewCell
var userName = cell.viewWithTag(1)! as UILabel
var timestamp = cell.viewWithTag(2)! as UILabel
var postBody = cell.viewWithTag(5)! as UILabel
var post = self.posts[indexPath.row]
userName.text = post.name
timestamp.text = post.timestamp
postBody.text = post.body
cell.setNeedsLayout()
cell.layoutIfNeeded()
return cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height
}
Why doesn't it work? With the UITableViewAutomaticDimension I got it working and conforming to the constraints I put through auto-layout, but can't get it here.