iosswiftuitableviewtableviewrow-height

UITableViewCell Size is not expanding at runtime .?


here is a storyboard image. i have take a dynamic tableviewcell I have tried with drag and drop UITableViewCell and change row height from the storyboard, it cannot expanded cell height at runtime.

In Xcode 9.0.1 and Swift 4, I am facing issues regarding cell height not increasing at runtime.so, pls help me for solving this issue.

enter image description here

enter image description here


Solution

  • To set automatic dimension for row height & estimated row height, ensure following steps to make, auto dimension effective for cell/row height layout.

    -

    @IBOutlet weak var table: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Don't forget to set dataSource and delegate for table
        table.dataSource = self
        table.delegate = self
    
        // Set automatic dimensions for row height
        table.rowHeight = UITableViewAutomaticDimension
        table.estimatedRowHeight = UITableViewAutomaticDimension
    }
    
    
    
    // UITableViewAutomaticDimension calculates height of label contents/text
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

    For label instance in UITableviewCell

    enter image description here