gpt4 book ai didi

ios - TableView Cell 内的多个 View

转载 作者:行者123 更新时间:2023-11-30 11:20:56 25 4
gpt4 key购买 nike

This is how my cell looks like

This is the structuring of my cell

我的 JSON 格式如下所示:

{
"status": true,
"session": true,
"make": "Ford",
"year": "2015",
"model": "EXPLORER",
"trim": "Base",
"engine": "3.5L V6 - Gas",
"make_id": "96",
"year_id": "100",
"model_id": "284",
"trim_id": "358",
"engine_id": "510",
"title": "Ford 2015 EXPLORER Base 3.5L V6 - Gas - Alternator",
"group_image": "http://www.orouad.com/test_aspns/image/catalog/Ford/67dc394bb5c7839fe09bcbae85210b90.svg",
"parts": [
{
"product_id": "7760",
"group_id": "317991",
"part_number": "DG1Z-10346-B",
"part_name": "Alternator",
"part_image": "http://www.orouad.com/test_aspns/image/cache/placeholder-130x130.png",
"description": "",
"part_index": "1",
"quantity": "0",
"price": "SAR 0.00",
"after_market": [],
"superseded": [
{
"part_id": "11695",
"part_no": "AA5Z*10346*B",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
},
{
"part_id": "12187",
"part_no": "GL*980*",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
}
]
},
{
"product_id": "7761",
"group_id": "318048",
"part_number": "DG1Z-10346-F",
"part_name": "Alternator",
"part_image": "http://www.orouad.com/test_aspns/image/cache/placeholder-130x130.png",
"description": "",
"part_index": "1",
"quantity": "0",
"price": "SAR 0.00",
"after_market": [],
"superseded": [
{
"part_id": "11581",
"part_no": "8A4Z*10346*A",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
},
{
"part_id": "12032",
"part_no": "DG1Z*10346*A",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
},
{
"part_id": "12186",
"part_no": "GL",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 7.00",
"quantity": "0"
}
]
},
{
"product_id": "7762",
"group_id": "318101",
"part_number": "GB5Z-10346-C",
"part_name": "Alternator",
"part_image": "http://www.orouad.com/test_aspns/image/cache/placeholder-130x130.png",
"description": "",
"part_index": "1",
"quantity": "0",
"price": "SAR 0.00",
"after_market": [],
"superseded": [
{
"part_id": "11848",
"part_no": "BL3Z-10346-A",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
},
{
"part_id": "12079",
"part_no": "DG1Z-10346-C",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 0.00",
"quantity": "0"
},
{
"part_id": "12186",
"part_no": "GL",
"manufacturer": null,
"description": "Alternator",
"price": "SAR 7.00",
"quantity": "0"
}
]
}

如果数组“售后”和“被取代”中有任何值,我想显示所有“零件”以及“售后”和“被取代”零件,否则隐藏售后和被取代 View 并仅显示零件 View 。

我的问题是如何显示售后市场的多个 View ,并在这些数组中有多个值时被取代。

此代码用于显示售后市场中是否只有一个值或已被取代

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return partsData.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "partsDetailCell") as! VehiclePartsDetailCell
cell.layer.borderColor = UIColor.white.cgColor
cell.layer.borderWidth = 1
let partData = partsData[indexPath.row]
if (partData.afterMarket?.isEmpty)!{
cell.bottomView.isHidden = true
}else{
cell.bottomView.isHidden = false
cell.bottomPartLbl.text = partData.afterMarket![0].partNo
cell.bottomDesLbl.text = partData.afterMarket![0].description
cell.bottomPriceLbl.text = partData.afterMarket![0].price
}
cell.serialNoLbl.text = partData.partIndex
cell.partNoLbl.text = partData.partNumber
cell.descriptionLbl.text = partData.partName
cell.priceLbl.text = partData.price
cell.cartBtn.setImage(UIImage(named: "cart.png"), for: .normal)
return cell
}

我有人提供有关如何填充数据或在表格 View 中使用多个单元格的任何建议。

最佳答案

这是伪代码,仅作为示例,您必须对其进行修改。首先,您必须使用此方法设置单元格大小

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return currentCellSize + partsData[indexPath.row].superseded.count * supersededSize + afmNormalHight * partsData[indexPath.row].afterMarket.count
}

之后,您需要将单元格创建更改为这样

var currentCount = 0
for afterMarket in partData.afterMarke {
let afm = AfterMarketView()
afm.bottomPartLbl.text = partData.afterMarket![0].partNo
afm.bottomDesLbl.text = partData.afterMarket![0].description
afm.bottomPriceLbl.text = partData.afterMarket![0].price
afm.frmae = CGFrame(0, normalCellSize + afmNormalHight * currentCount, cell.frame.size.width, afmNormalHight)
currentCount++
cell.addSubview(afm)
}

关于ios - TableView Cell 内的多个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51278269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com