![](/img/trans.png)
[英]Is it possible to implement tableview inside tableview cell in swift 3?
[英]How to implement a tableview cell that contains 2 more cells inside counts are not same
我的表格视图有 3 个单元格(SubItemsCell(主单元格)、SubItemsListCell(主单元格内的产品数量)和 noSubstituteCell(第二个单元格计数 1 后的固定单元格))
SubItemsCell 有一个“SELECT”按钮,它将展开并显示 SubItemsListCell,此单元格将作为(动态)主 SubItems 单元格下的任何产品计数加载。
NoSubstitute Cell 出现在 n 个产品加载之后。
我的预期结果是首先加载主单元格,即 self.archivedProducts,当您单击每个归档产品的 select 按钮时,它会展开并加载 self.newproducts 并且没有替代 static 单元格。 因此,主单元格与这两个单元格配对,并且仅在我们扩展时立即显示。
到目前为止,我只加载了 Main Cell。 我不知道下一步该怎么做,请用代码或非常相似的例子给我一个想法。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "SubItemsCell", for: indexPath) as? SubItemsCell else {
fatalError ("SubstituteItems Cell not found!")
}
let product = self.archivedProducts[indexPath.row]
cell.titleLabel.text = product.title ?? ""
cell.priceLabel.text = "AED \(String(format: "%.2f", product.price ?? 0.00))"
cell.scaleLabel.text = product.uom ?? ""
cell.unavailableLabel.isHidden = false
cell.selectBtn.isHidden = false
let imageUrl = product.image?.url
let escapedUrl = imageUrl?.replacingOccurrences(of: "\\", with: "")
let replacedUrl = "\(escapedUrl ?? "")"
let url = URL(string: replacedUrl)
let plImage = UIImage(named: "whiteBg")
DispatchQueue.main.async {
cell.thumbImage.kf.setImage(with: url, placeholder: plImage, options: [.transition(.fade(0.2))])
}
}
我认为您不需要嵌套的表格视图。 您可以通过其他元素实现上述目标。 为了实现上面的布局,我的建议如下:
一个。 CellWDropdown(显示了单元格#1):您有一个单元格原型,其中包括图像、有问题的 3 个标签和一个用作下拉菜单并调用 UIPickerView 的按钮。
湾。 CellWStepper(单元格 #2 和 #3):您将拥有图像和 2 个标签,以及用于 +/- 按钮的所谓 UIStepper
c。 LastCell(如果是单元格,则为单元格#4?它也可以是视图):同样创建所需的 UI 元素并适当地约束它们。
tableView.register(UINib(nibName: "CellWDropDown", bundle: nil), forCellReuseIdentifier: "cellWDropdownIdentifier")
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: cellWDropdownIdentifier, for: indexPath) as! CellWDropdown
}
else if(indexPath.row == 1 || indexPath.row == 2){
let cell = tableView.dequeueReusableCell(withIdentifier: cellWStepperIdentifier, for: indexPath) as! CellWStepper
}
//do other actions/styling
}
有很多细节需要填补空白,但这应该会对入门产生重大影响
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.