0

i have table view inside table view cell, need to set table view height depending on table view content, i tried below code

extension tableViewCell: UITableViewDelegate{
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
            lcOptionsTVHeight.constant = tableView.contentSize.height
        }
    }
}

but this is not working in first load, but updating as i do scroll up and down, how can do load in properly in first load itself?

KEERTHI j
  • 220
  • 3
  • 15

1 Answers1

0

heightForRowAt(:)

You need to pass your height in heightForRowAt(:)

In this method, you need to check if it's the nested tableview cell and return the height, in other cases just return UITableView.automaticDimension

My suggestion would be to use sections instead of nested tableview. Only if there's horizontal scrolling requirement(not the case here as you mentioned tableview inside a tableview cell), we can go with a collectionview inside tableview cell.

Here, using different sections might be sufficient. You can reload sections by tableView.reloadSections

Again it might be dependent on your requirement. In general, we don't see tableview inside a tableview cell.

Cribber
  • 2,513
  • 2
  • 21
  • 60
Teju Amirthi
  • 174
  • 6