如何快速将标题视图添加到每个自定义 tableViewCells

我有两个自定义的 TableViewCell。所以第一个 TableViewCell 就像一个最近的列表,它可以变得更长。但第二个单元格总是停留在底部。所以我需要添加持有 secondTableViewCell 的 UILabel。 the result that i need

FieldMask
raytacer 回答:如何快速将标题视图添加到每个自定义 tableViewCells

这是提供解决方案的另一种尝试。这是您要找的吗?

这是项目的链接 https://drive.google.com/file/d/1XlSF4fGiNzOqQHauiNo7TuFhKUTrFbsJ/view?usp=sharing

如果您需要更多帮助,请告诉我

screen shot

,

晚上好,所以我按照您的图片制作了代码,并遵循您的 1 个表格视图部分和 2 个不同单元格的约定。我尝试使用您的命名约定。请注意,我必须交换高度值,您的方法错误。

   class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
        @IBOutlet weak var tableView: UITableView!
        var itemsName: [String] = ["Helmet","Gloves","Bindings","Goggles","Kneepads","Boots","Snowboard"]
        
        override func viewDidLoad() {
            super.viewDidLoad()
        }
        
        func numberOfSections(in tableView: UITableView) -> Int {
            return 1
        }
    
        func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
            return 1 + itemsName.count
        }
        
        func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            
            if indexPath.row < itemsName.count{
                let bagTableViewCell = tableView.dequeueReusableCell(withIdentifier: "BagTableViewCell") as? BagTableViewCell
                bagTableViewCell?.productsLabel.text = itemsName[indexPath.row]
                return bagTableViewCell!
            } else {
                let extraBagPageTableView = tableView.dequeueReusableCell(withIdentifier: "ExtraBagPageTableView") as? ExtraBagPageTableView
                return extraBagPageTableView!
            }
        }
        
        func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat {
            if indexPath.row < itemsName.count {
                return 50
            } else {
                return 165
            }
        }
    }

还有 tableview 单元格。请注意,第二个单元格的名称不正确。

class BagTableViewCell: UITableViewCell {
    @IBOutlet weak var additionalProductsLabel: UILabel!
    @IBOutlet weak var productsLabel: UILabel!
    @IBOutlet weak var productImage: UIImageView!
}

class ExtraBagPageTableView: UITableViewCell {
    
}

总的来说就是这个样子

enter image description here

该项目可以在这里找到。 (我这次正确设置了权限 :) )

TableCellWithLabel Project

本文链接:https://www.f2er.com/852464.html

大家都在问