Search code examples
swift4.1

Cell Data not showing properly in table view swif4


I am using table view inside table view I have used some views and then I used cell but when i running in simulator its content not showing properly I added screenshot please check it.

func numberOfSections(in tableView: UITableView) -> Int
{
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return tc_array.count
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
    print(b_description.bounds.size.height)
    return 200 + b_description.bounds.size.height

    // return UITableViewAutomaticDimension
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let cell : TermCell = tableView.dequeueReusableCell(withIdentifier: "TermCell", for : indexPath as IndexPath) as! TermCell

     cell.tc_lebel.text! = tc_array[indexPath.row]

     print(cell.tc_lebel.text!)

     return cell
}

new image click on it 2: https://i.sstatic.net/Lwd8o.png . check it new image

[1]: https://i.sstatic.net/I9rYO.png constraint image


Solution

  • If you have placed your constraints correctly, I would suggest removing

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
    {
    
        print(b_description.bounds.size.height)
        return 200 + b_description.bounds.size.height
    }
    

    And when you setup your view, in viewDidLoad you should add this for automatic row dimension

     tableView.rowHeight = UITableViewAutomaticDimension
     tableView.estimatedRowHeight = yourAverageCellRowHeight