-3

If I want to change the height of UITableView as per the cell content changes i.e. the height of UITableViewCell increase as API response come different every time? Please help me to find out a solution?

Kiran Jadhav
  • 3,209
  • 26
  • 29

2 Answers2

2

If your receiving response in array then you can increase the height with array counts by reload your table view tableView.reloadData() when you are receiving the responses.

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

 if indexPath.section == 0 {
  switch indexPath.row {
  case 0:
    return 50
  case 1:
    return 60
  case 2:
    if array.count > 0{
      return (CGFloat(45* array.count))
    }else{
      return 0
    }
   default:
    return 0
   }
 }
}
Naren Krish
  • 259
  • 2
  • 14
1
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let key = arrInfo[indexPath.row]["key"] as! String
        print("height for row key \(key)")
        if key == "CasinoInfo"{
            return 100  
        }
        else if key == "Ratings"{
            return 180
        }
        else if key == "Bonus"{
            return 120
        }
        else{
            return UITableViewAutomaticDimension
        }

        return 0
    }