UITableView within a UITableViewCell with dynamic height

前端 未结 3 1977
执笔经年
执笔经年 2021-01-27 07:50

So I\'m trying to build something rather intricate - potentially more than what the picture below shows. Anyway..

I\'m trying to have a UITableView inside o

3条回答
  •  佛祖请我去吃肉
    2021-01-27 08:31

    You can do with Observer, please try if it works

    1. You have to add to tableview (which is in tableCell)

    yourTableView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOptions.old, context: nil)
    

    2. Method that observe changes

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
    
         //height can be use as cell height,
        let height = yourtableview.contentSize.height;
    }
    
    deinit {
         yourtableview.removeObserver(self, forKeyPath: "contentSize")
    }
    

提交回复
热议问题