1

edit: I think this may have something to do with iOS 8.3. This doesn't occur on the simulator and none of my testers have the problem but my dev phone with 8.3 on it does. Any ideas on how to fix it?

edit2: I found an answer here https://stackoverflow.com/a/36711109/1552116. I've answered this SO below and will accept in 2 days but I guess this is technically a duplicate?

I have a UITableView with rowHeight set to UITableViewAutomaticDimension

Each cell contains multiple labels, one of which can be multi line. Sometimes, the cell displays correctly with the label taking up multiple lines. Other times, the cell is sized correctly but the label only takes up one line, leaving a big empty space where the other lines should have gone.

The tableview is backed by a NSFetchedResultsController.

Picture to show what I mean (to be clear "Expected" is not a rendering, it's an actual screenshot of the app working some of the time) enter image description here

Things I've tried + Thoughts

There's a refresh action on the page and I've tried tableView.reloadData(), tableView.setNeedsLayout() and both don't seem to help

I've noticed if I'm on the tableView when the notification is created, it displays correctly. If I force quit the app (or run the app again from XCode) and the cells are initialized from the fetch result, then they get displayed erroneously.

This app is also on testflight and of the ~5 testers we have none of them have reported the issue.

Edits Answering comments

Code that sets the label cellForRowAtIndexpath

let cell = tableView.dequeueReusableCellWithIdentifier(StoredNotificationViewController.snTableViewCellReuseIdentifier, forIndexPath: indexPath) as! StoredNotificationTableViewCell
configureCell(cell, atIndexPath: indexPath)

configureCell

    let storedNotification = snFetchedResultsController.objectAtIndexPath(indexPath) as? StoredNotification
    cell.setData(storedNotification)

cell.setData

    messageLabel.text = notification.message
Community
  • 1
  • 1
wyu
  • 1,793
  • 17
  • 33
  • Can you post the code where setting the table cell's title – Janmenjaya Sep 16 '16 at 17:56
  • @Janmenjaya that code is just `messageLabel.text = notification.message` notification is an entity from core data. messageLabel is a UILabel configured in storyboard with numberOfLines = 0 – wyu Sep 16 '16 at 18:06
  • The fetching from core data is closure or completion block, i guess. If so just try to reload the table or put some sleep time to set that data to label, i guess the issue must be due to the secondary thread . let me know the result – Janmenjaya Sep 16 '16 at 18:12
  • What is your estimated row height? – Bista Sep 16 '16 at 18:24
  • I think I understand what you're saying @Janmenjaya I'll update the question with the code – wyu Sep 16 '16 at 18:32
  • @Mr.UB estimated row height is 160 – wyu Sep 16 '16 at 18:37
  • Can you also tell me the height of 1st and 2nd cell of the last image i.e bugged w/ view frames? – Bista Sep 16 '16 at 18:40
  • @Mr.UB sorry I couldn't get to you sooner, I found the solution - it's a problem with iOS8, see accepted answer for solution – wyu Sep 16 '16 at 21:28

2 Answers2

6

The answer is here https://stackoverflow.com/a/36711109/1552116

Basically, you add cell.updateConstraintsIfNeeded() to the end of your tableView(_:cellForRowAtIndexPath:) method

Community
  • 1
  • 1
wyu
  • 1,793
  • 17
  • 33
0

Make sure all of your constraint are connected to edges of the Cell , so it knows whats it's height.If you have done that than try setting the vertical Content Hugging Priority to 751 and Vertical Content Compression Resistance Priority to 751 of that Label. Also you can set the bottom constraint priority of that label to 750. Let me know if that helped you.

unniverzal
  • 803
  • 10
  • 17
  • my constraints are connected as evident in the "expected" screenshot, but I'll give the compression resistance and content hugging a shot – wyu Sep 16 '16 at 18:48
  • gave content hugging a shot, no dice – wyu Sep 16 '16 at 21:20