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?
Asked
Active
Viewed 203 times
-3
-
Take the outlet of height constraint of tableView in viewController, then calculate the height and assign to that constraint, e.g. self.heightConstraint.constant = 200; – bunty Dec 08 '17 at 04:50
-
Do you not want the table view to be scrolling ? – GoodSp33d Dec 08 '17 at 04:51
-
@Tushar Sharma : Not give the proper solution as I want, Please check? – Kiran Jadhav Dec 08 '17 at 04:55
-
@GoodSp33d : I don't want to be height fix & it will changes as per tableview cell content height. – Kiran Jadhav Dec 08 '17 at 04:55
-
check auto layout for uitbaleviewcell with label having number of line as Zero – Vinodh Dec 08 '17 at 06:09
-
@Kiranjadhav, what type of content you want to display with dynamic height? Label, images, and other? – Kuldeep Dec 08 '17 at 06:23
-
@ Kuldeep: UIlabel[Name] + UILabel[Count] + UIImage[icon] – Kiran Jadhav Dec 08 '17 at 06:36
2 Answers
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
}

Jaydeep Paghdar
- 31
- 2