[英]How to set the dynamic height of table view cell with nested table views in ios.?
I am working on a nested table view.我正在处理嵌套表格视图。 with 3 table views one inside another, the two of the table views were working properly but the super table view's cells were not adjusting as per the respective content size.
有 3 个表视图一个在另一个表视图中,两个表视图工作正常,但超级表视图的单元格没有根据各自的内容大小进行调整。 even I used.
连我都用过。
UITableView.automaticDimension
1st tableView in UIViewController
第一张表在 UIViewController 中查看
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
let count = AllTaskManager.shared.futureListArray.count
isNoData(count: count)
print(count)
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "FutureAppointCell") as! FutureAppointCell
cell.setData(index: indexPath.row)
cell.delegate = self
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
return UITableView.automaticDimension
}
2nd TableView inside the
FutureAppointCell
FutureAppointCell
中的第二个 TableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
tableHight.constant = CGFloat(AllTaskManager.shared.futureListDateArray.count * (Int(internalCellHeight) + 250))
self.delegate?.cellHeight(tableHight.constant)
return AllTaskManager.shared.futureListDateArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "FutureAppoinmentDayCell") as! FutureAppoinmentDayCell
cell.setData(index: indexPath.row)
cell.delegate = self
buttonTag = indexPath.row
let startDate = AllTaskManager.shared.convertStringToDate(string: cell.dateFullName)
print("\(startDate) is the date" )
if startDate.month >= Date().month{
if startDate.month == Date().month{
if startDate.day == Date().day{
cell.cancelBTN.isHidden = true
cell.addToCalenderBTN.frame.size.width = 20
}else{
cell.cancelBTN.isHidden = false
cell.cancelBTN.addTarget(self, action: #selector(cancelBtn(sender:)), for: .touchUpInside)
}
}else {
cell.cancelBTN.isHidden = false
cell.cancelBTN.addTarget(self, action: #selector(cancelBtn(sender:)), for: .touchUpInside)
}
}else {
cell.cancelBTN.isHidden = true
}
cell.addToCalenderBTN.addTarget(self, action: #selector(addToCalendar(sender:)), for: .touchUpInside)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
return UITableView.automaticDimension
}
3rd Table view in
FutureAppoinmentDayCell
FutureAppoinmentDayCell
中的第 3 个表视图
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
tableHeight.constant = CGFloat(count * 65)
self.delegate?.cellHeight(tableHeight.constant)
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "FutureNoBtnTableViewCell", for: indexPath) as! FutureNoBtnTableViewCell
print(getDict(subIndex: indexPath.row))
let dict = getDict(subIndex: indexPath.row)
cell.employeeLBL.text = dict.value(forKey: "serviceDisplayName") as? String
let time = AllTaskManager.shared.getSubHeaderTimeForPastFutureName(string: dict.value(forKey: "startDateTime") as! String)
cell.timeLBL.text = time
cell.appointmentId = dict.value(forKey: "appointmentId") as? String
cell.id = dict.value(forKey: "id") as? String
cell.time = dict.value(forKey: "startDateTime") as? String
if let startDate = dict.value(forKey: "startDateTime") as? String {
let date = AllTaskManager.shared.convertStringToDate(string: startDate )
if date.year == Date().year{
if date.month == Date().month{
if date.day == Date().day{
//"transitionStateDisplayValue": "Checked In", "transitionStateDisplayValue": "Booked",
if let checkiInStatus = dict.value(forKey: "transitionStateDisplayValue") as? String{
cell.delegate = self
if checkiInStatus == "Checked In"{
cell.checkInBTN.isHidden = true
cell.checkedInLBL.isHidden = false
}else{
cell.checkInBTN.setTitle("Check-In", for: .normal)
}
}else{
cell.checkInBTN.isHidden = true
}
}else {
cell.checkInBTN.isHidden = true
}
}else{
cell.checkInBTN.isHidden = true
}
}else{
cell.checkInBTN.isHidden = true
}
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
return 60
}
I often use stack views in table view cells, and adjust cell height according to stack view.我经常在表格视图单元格中使用堆栈视图,并根据堆栈视图调整单元格高度。 Maybe this will solve your problem
也许这会解决你的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.