表格视图单元格大小的自动尺寸

时间:2020-06-22 11:07:48

标签: xcode uitableview tableview swift4 swift5

我是iOS新手。我在一个Table视图内实现了Collection视图,该视图也在另一个Table视图中。现在,我必须动态地使两个Table视图的单元格大小。这意味着第二个表的单元格大小应根据“集合”视图的高度而定。并且第一个表格视图单元格的大小应根据第二个表格视图的高度。因此,我为此使用了以下函数或语句。

对于第一个表格视图,

override func viewDidLoad() {
    super.viewDidLoad()

      self.cartTable.rowHeight = UITableView.automaticDimension
       self.cartTable.estimatedRowHeight = 999
  }

  override func viewWillAppear(_ animated: Bool) {
       
       
       self.cartTable.rowHeight = UITableView.automaticDimension
       self.cartTable.estimatedRowHeight = 999
       
      
   }

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

第二个表格视图的一个

override func awakeFromNib() {
    super.awakeFromNib()
    
    self.cartSlotTable.rowHeight = UITableView.automaticDimension
    self.cartSlotTable.estimatedRowHeight = 999
    
    // Initialization code
}

 override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    
    self.cartSlotTable.rowHeight = UITableView.automaticDimension
    self.cartSlotTable.estimatedRowHeight = 999
    
    // Configure the view for the selected state
}

  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
       return UITableView.automaticDimension
   }


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

但是这些对我不起作用,单元格正在崩溃,并且表格视图的高度为零。

预先感谢。

0 个答案:

没有答案
相关问题