ios - heightForRowAtIndexPath Not working properly -
i trying display image correct aspect ratio in tableview. have pre-calculated aspect ratio of image, , seems work on actual image, not on cell displayed in.
code image in cell:
private var cellimage: uiimage? { { return cellimageview.image } set { cellimageview?.image = newvalue if let newimage = newvalue { heightconstraint.constant = newimage.size.width / cgfloat(aspectratio) } } }
code in tableview:
override func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { return tableview.bounds.size.width / cgfloat(aspectratio) }
aspectratio variable same in both. aspectration = width/height of image. also, checked see height received in both places same, , same value (in runtime).
anyone know why cell height not set correctly?
you can use dynamic cell height , make cell fit imageview inside check tutorial https://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift
Comments
Post a Comment