ios - UITableViewCell dynamic height does not work with size classes -


setting estimatedrowheight , rowheight of uitableview makes table view calculate proper height of each cell. works charm until use size classes. seems calculations being done any/any size class , bigger font applied later. result height of cell not calculated , label doesn't fit.

here code:

class viewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource {      @iboutlet weak var tableview: uitableview!      override func viewdidload() {         super.viewdidload()          self.tableview.estimatedrowheight = 50         self.tableview.rowheight = uitableviewautomaticdimension     }      func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return 3     }      func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         let cell = tableview.dequeuereusablecellwithidentifier("reuse", forindexpath: indexpath) as! mytableviewcell         println("label font size: \(cell.mylabel.font)") // prints (...)font-size: 11.00pt size classes         return cell     } } 

layout looks that: table view layout

and usage of size classes is: font size classes

now, when open app on iphone looks expected. on ipad cells not resized. in fact resized fit text if font size 11pt instead of 40pt.

the question is: how can force calculations performed after size classes applied?

i tried trick overriding trait collection suggested in: https://stackoverflow.com/a/28514006 didn't work. mean, size class read (regular/regular) font size still 11pt.

you can download simple project github: https://github.com/darecki/tableviewtest

screenshots:

  • iphone 4s:

enter image description here

  • ipad 2:

enter image description here

  • ipad 2 after calling tableview.reloaddata():

enter image description here

edit: formatting, added github link.

set preferred max width on label in interface builder - > size inspector. solves issue me. make sure number of lines 0.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -