Reputation: 61
I Just create UITableview
(Second UITableview
) inside UItableviewcell
. I need to increase UItableviewcell
height based on second UITableview number of cell(second UITableview's
cells had a different height).
1st tableview:
extension ViewController:UITableViewDelegate, UITableViewDataSource{
// no of row #1
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderTimelineCell", for: indexPath) as! OrderTimelineCell
return cell;
}
}
1st tableview Cell:
override func awakeFromNib() {
tableView.layoutIfNeeded()
tableView.heightAnchor.constraint(equalToConstant: tableView.contentSize.height).isActive = true //always return 44*#cells
}
extension OrderTimelineCell:UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineTableViewCell", for: indexPath) as! TimelineTableViewCell
cell.label.text = array[indexpath.row] // text height different
return cell
}
}
I expect output to display all cells of Second UITableview
inside 1st UITableview
cells.
but the actual output is cell height == #no of cell * 44
Upvotes: 0
Views: 65
Reputation: 1818
You need to specify height in this method:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == indexOfExtendedCell {
return 100 // or another height
}
return 44
}
Upvotes: 1