【发布时间】:2018-07-11 06:05:54
【问题描述】:
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"
}
]
}
如果数组“aftermarket”和“superseded”中有任何值,我想显示所有“零件”以及“售后市场”和“取代”零件,否则隐藏售后市场和被取代视图并仅显示零件视图。
我的问题是,如果这些数组中有多个值,我如何显示售后市场的多个视图并被取代。
这是显示售后市场是否只有一个值或已被取代的代码
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
}
我有任何人提供有关如何填充数据或在 tableview 中使用多个单元格的任何建议。
【问题讨论】:
-
提及您需要的部分数量和 cellForRowAt indexPath: 在每个部分中创建多个单元格。 if indexPath.section = 0 { //第一个模型单元格 } else if indexPath.section = 1 { //显示第二个模型单元格 } else {//显示第三个模型单元格}
-
我不想创建单独的部分,我只想显示售后市场和被取代的部分,如果有任何价值,或者只是隐藏它们。其他部分也像这样。
标签: ios swift uitableview uiview