Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic Tableview inside UItableViewCell

I want to implement subTableView with dynamic height inside the UITableViewCell, where as the subTableView has cells with dynamic UITableViewCell.Please share your thoughts on this if anybody have implemented this scenario.

-UItableview(Parent)
  -UItableviewCell
     -UITableView(child)
        -UItableviewCell(dynamic content).
like image 448
user1068810 Avatar asked Sep 16 '25 09:09

user1068810


1 Answers

First Approach: Create a subclass for child tableView and override intrinsicContentSize.

         class MyOwnTableView: UITableView {
        override var intrinsicContentSize: CGSize {
            self.layoutIfNeeded()
            return self.contentSize
        }

        override var contentSize: CGSize {
            didSet{
                self.invalidateIntrinsicContentSize()
            }
        }

        override func reloadData() {
            super.reloadData()
            self.invalidateIntrinsicContentSize()
        }
    }

2. In Interface builder change the class of your child tableView to MyOwnTableView (subclass UItableView).

  1. Set automatic row height for both the parent and child table view.

        tableView.estimatedRowHeight = 60.0;
        tableView.rowHeight = UITableViewAutomaticDimension;
    

Second Approach: 1. Create a height constraint with any value for child tableView and conect an IBOutlet that sets the child tableView height. 2. Set the height constraint's constant to tableView.contentSize.height

    self.tableViewHeight.constant = self.tableView.contentSize.height
like image 90
Learner Avatar answered Sep 18 '25 16:09

Learner