我有一种情况,我必须为单个tableView使用两个不同的原型单元。这两个原型单元具有不同的高度。当我尝试运行该应用程序时,没有得到不同高度的单元格。相反,我正在重叠细胞。单元格在索引2处相互重叠。
我为单元格制作了两个xib,并在tableview中注册了两个单元格。我得到的屏幕截图
extension Redeem: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0{
let cell1 = tableView.dequeueReusableCell(withIdentifier: "RedeemCell1", for: indexPath) as! RedeemCell1
return cell1
} else if indexPath.row == 1{
let cell1 = tableView.dequeueReusableCell(withIdentifier: "RedeemCell1", for: indexPath) as! RedeemCell1
return cell1
} else if indexPath.row == 2{
let cell2 = tableView.dequeueReusableCell(withIdentifier: "RedeemCell2", for: indexPath) as! RedeemCell2
return cell2
} else if indexPath.row == 3{
let cell1 = tableView.dequeueReusableCell(withIdentifier: "RedeemCell1", for: indexPath) as! RedeemCell1
return cell1
} else {
let cell1 = tableView.dequeueReusableCell(withIdentifier: "RedeemCell1", for: indexPath) as! RedeemCell1
return cell1
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
}
我认为,单元的布局不正确。
要定义单元格的高度,您需要一个不间断的约束和视图链(具有定义的高度),以填充内容视图的顶部边缘与其底部边缘之间的区域。
如果在单元格中使用XIB,则可以更改单元格中的模拟大小,然后查看发生了什么。该单元应该没有打破的约束。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句