的UITableViewCell是空当的tableview滚动上攻
问题描述:
- 首先图像时,我不滚动的tableView
MY子项目是显示的UITableViewCell是空当的tableview滚动上攻
- 第二次图像当我滚动表查看
MY子项都是空白
我CellFor行代码是
var aryDictData = [[String:AnyObject]]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var aryOptionName = [String]()
var strOptionName = String()
var cell = DeliveryTableViewCell()
cell = tableView.dequeueReusableCell(withIdentifier: "DeliveryTableViewCell") as! DeliveryTableViewCell
cell.selectionStyle = .none
let productPrice = userDefault.object(forKey: ProductDesConstantNames.KAryStorePrices) as! [String]
if indexPath.section == 0{
if indexPath.row < (aryDictData[0]["storeName"]!).count{
cell.lblItemName.text = ((aryDictData[0]["storeName"]! as AnyObject)[indexPath.row] as! String)
cell.lblPrice.text = "$\(String(((Double(productPrice[indexPath.row])! + grandTotalProductPrice[indexPath.row]) * Double(numQuntity))))"
cell.lblItemQuantity.text = "\(numQuntity)x"
cell.lblItemQuantity.textColor = UIColor.init(red: 41/255, green: 144/255, blue: 85/255, alpha: 1.0)
let data = aryPreviewOrder[indexPath.row] as! [[String:AnyObject]]
print(data)
for i in 0..<((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject).count {
let optionName = ((((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject)[i] as AnyObject)["option_name"] as! String)
let prices = ((((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject)[i] as AnyObject)["price"] as! String)
aryOptionName.append("\(optionName) ($\(prices))")
// aryOptionPrices.append("($\(prices))")
strOptionName = aryOptionName.joined(separator: "\n")
// strOptionPrice = aryOptionPrices.joined(separator: "\n")
}
cell.lblOptionNames.text = strOptionName
}
}
}
return cell
}
答
尽量避免for循环中的行中的单元格,同时建立数据源,您可以创建这些选项名称并使用某个键将其存储在数组中,然后每次在cellforrow中重用该键,而不是再次创建n。
for i in 0..<((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject).count {
let optionName = ((((aryDictData[0]["options"]! as AnyObject)
[indexPath.row]! as AnyObject)[i] as AnyObject)["option_name"] as!
String)
let prices = ((((aryDictData[0]["options"]! as AnyObject)
[indexPath.row]! as AnyObject)[i] as AnyObject)["price"] as! String)
aryOptionName.append("\(optionName) ($\(prices))")
}
strOptionName = aryOptionName.joined(separator: "\n")
cell.lblOptionNames.text = strOptionName
+0
我试过但不工作 – Prototype
请添加代码在你cellforrow – KavyaKavita
,我就迅速3 – Prototype
工作是你确保你能获得在'strOptionName'每一次数据?,写cell.layoutIfNeeded(),之后cell.lblOptionNames.text = strOptionName并在该行之前 –