TableView Automatic Dimension Tableview Inside Tableview

前端 未结 4 2047
慢半拍i
慢半拍i 2020-12-19 12:47

I have Tableview for showing food orders placed by clients. which contains Horizontal UIStackview. In UIStackView

In UIStackview

4条回答
  •  鱼传尺愫
    2020-12-19 13:30

    I have tried almost all the possible solutions but each has some problems. So I have found another workaround to fix this It can not be called perfect solution but yes it works for me

    In tableview cell, I have added One Hidden Label which is Top : 0 , Bottom : 0 , left : 0 and right : 0

    Now

        // This is temp label which help to calulate height to tableview
        if let orderMaster = restObj.orderDataMaster {
    
            var tempText = ""
            for orderMasterObject in orderMaster {
    
                tempText += (orderMasterObject.item?.name ?? "") + "\n" + "  "
    
                if let subItems = orderMasterObject.masterSubitem {
    
                    let result = subItems.reduce("", { (result, subItem) -> String in
                        return result +  (subItem.subitem?.name ?? "") + ","
                    })
                    tempText += result + "\n" + "  "
    
                }
                tempText += "\n"
            }
            cell.lblTemp.text = tempText
        }
    
        self.view.layoutIfNeeded()
        cell.setNeedsLayout()
        cell.delegate = self 
    

    What here done is, Inner tableview's cell has labels which grow as per text. So That temp label has same text (masterSubitem) in my case, in short I have replicated inner tableview cell in that label as we have provided All Four constrains to label so when it will grow our tableview cell will grow along with it.

    Hope it is helpful to someone who is facing the same issue If any of you can post another working solution I will happily accept it :)

提交回复
热议问题