hellosheikh hellosheikh - 1 year ago 124
iOS Question

Self sizing TableView cell with image and label

hello I have a dynamic TableViewController in which there is one cell which has one image, and labels. I have set constraint of all of them. The problem is its not viewing correctly.

enter image description here

This is how its viewing

enter image description here


override func viewDidLoad() {
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 103


override func viewWillAppear(animated: Bool) {


override func viewDidAppear(animated: Bool) {


override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1


override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return newarray.count

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("requestcell", forIndexPath: indexPath) as! NewRequestTableViewCell

let image : UIImage = UIImage(named: "placeholder_product_image")!
cell.imageView!.image = image
cell.requestTitle.text = "IPHONE 6s PLUS"
cell.DestinationCountry.text = "Pakistan"

return cell


I don't know what else to do. Please help how can I have row like I designed

Answer Source

The problem here is the height of your cell add the following methods in your code: (replacing of course <#cell_height#> by the value of your choice, or by UITableViewAutomaticDimension)

override func tableView(_ tableView: UITableView,
heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    return <#cell_height#>;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download