根据ios swift 3中的内容设置UITableViewCell高度

根据ios swift 3中的内容设置UITableViewCell高度,uitableview,swift3,tableviewcell,Uitableview,Swift3,Tableviewcell,我正在创建一个tableView,并在CellforRowat中创建动态UILabel 现在UILabel可以是n倍,我想根据TableViewCell中创建的标签设置单元格的高度 请查看下面的屏幕截图: 我已经尝试过这个解决方案,但它对我不起作用 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return UITableViewAuto

我正在创建一个tableView,并在CellforRowat中创建动态UILabel 现在UILabel可以是n倍,我想根据TableViewCell中创建的标签设置单元格的高度

请查看下面的屏幕截图:

我已经尝试过这个解决方案,但它对我不起作用

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension;

    }
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 300

    }
此外,我还尝试在viewdidload上添加rowheight和估计的rowheight,但没有像这样对我有效

tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 300
我在cell forrowat中创建了如下标签:

   let AllCompanydict = ["CommonKey": CommonKey , "Company": companyname, "Participants": self.Contacts] as [String : Any]
                            self.AllCompanydicArray.append(AllCompanydict)


     for i in 0..<AllCompanydicArray.count {
                let commonkey = ((AllCompanydicArray[i] as NSDictionary).value(forKey: "CommonKey") as! String)
                if(commonkey == cell.lblCommonKey.text){


                if(isFirstTime == false){
                    RowHeight = RowHeight + 30.0
                    CellHeight = CellHeight + 30.0
                }
                else{
                    isFirstTime = false
                }
                let Company = (AllCompanydicArray[i] as NSDictionary).value(forKey: "Company") as! String
                let Contacts = (AllCompanydicArray[i] as NSDictionary).value(forKey: "Participants") as! [String]
               // section.append(Company)
                //items.append(Contacts)
                 var newLabel = UILabel(frame: CGRect(x: 10.0, y: RowHeight, width:cell.frame.width, height: 30.0))
                newLabel.text = Company
                newLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 13)
                cell.addSubview(newLabel)

                for j in 0..<Contacts.count {
                    RowHeight = RowHeight + 30.0
                    CellHeight = CellHeight + 30.0

                newLabel = UILabel(frame: CGRect(x: 10.0, y: RowHeight, width:30, height: 30.0))
                    newLabel.text = CaptionName(Name: Contacts[j])
//"RC"
                newLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 11)
                newLabel.textAlignment = .center
                newLabel.backgroundColor = getColorByHex(rgbHexValue: 0x002366, alpha: 0.9)// UIColor(red: 0.0, green: 14.0, blue: 40.0, alpha: 100.0)
                newLabel.layer.cornerRadius = (newLabel.frame.size.width) / 2
                newLabel.layer.borderWidth = 1.0
                newLabel.clipsToBounds = true
                newLabel.textColor = UIColor.white
                newLabel.layer.borderColor = UIColor.white.cgColor

                cell.addSubview(newLabel)

                newLabel = UILabel(frame: CGRect(x: 50, y: RowHeight, width:cell.frame.width-30, height: 30.0))
                newLabel.text = Contacts[j]//"Raghav Chopra"
                newLabel.font = UIFont(name:"HelveticaNeue", size: 13)
                cell.addSubview(newLabel)

                }
            }
        }
将AllCompanydict=[“CommonKey”:CommonKey,“Company”:companyname,“参与者”:self.Contacts]设为[String:Any]
self.AllCompanydicArray.append(AllCompanydict)
因为我在0。。
请告诉我前进的方向

提前谢谢

我如何解决这个问题