Reputation: 29
Using swift5 i tried below code but unable to make it a adjustable height of cell. Any one can help me in that?
tableView.rowHeight = tableView.frame.height/8
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
tableView.estimatedRowHeight = 100
return UITableView.automaticDimension
}
what I want
View Architecture
Upvotes: 0
Views: 106
Reputation: 14935
You need to confirm to UITableViewDelegate
and then call these two methods.
func tableView(UITableView, heightForRowAt: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
tableview.rowHeight = UITableView.automaticDimension
tableview.estimatedRowHeight = 100
But in both cases, it is required the views in cell have both bottom and top constraints. Read the accepted answer of this question for more info.
Configuring Cell Height and Layout
Upvotes: 1