ios - 在表格 View 中向上滚动时 UITableViewCell 为空
<p><ul>
<li><strong>我不滚动 tableView 时的第一张图片</strong></li>
</ul>
<p>我的子项目正在显示</p>
<p> <a href="/image/s0rDr.png" rel="noreferrer noopener nofollow"><img src="/image/s0rDr.png" alt="MY SubItems are Show"/></a> </p>
<ul>
<li><strong>滚动tableView时的第二张图片</strong> </li>
</ul>
<p>我的子项目是空白的</p>
<p> <a href="/image/1GRxc.png" rel="noreferrer noopener nofollow"><img src="/image/1GRxc.png" alt=" MY SubItems are blank "/></a> </p>
<p>我的 CellFor 行代码是 </p>
<pre><code>var aryDictData = []()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var aryOptionName = ()
var strOptionName = String()
var cell = DeliveryTableViewCell()
cell = tableView.dequeueReusableCell(withIdentifier: "DeliveryTableViewCell") as! DeliveryTableViewCell
cell.selectionStyle = .none
let productPrice = userDefault.object(forKey: ProductDesConstantNames.KAryStorePrices) as!
if indexPath.section == 0{
if indexPath.row < (aryDictData["storeName"]!).count{
cell.lblItemName.text = ((aryDictData["storeName"]! as AnyObject) as! String)
cell.lblPrice.text = "$\(String(((Double(productPrice)! + grandTotalProductPrice) * 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 as! []
print(data)
for i in 0..<((aryDictData["options"]! as AnyObject)! as AnyObject).count {
let optionName = ((((aryDictData["options"]! as AnyObject)! as AnyObject) as AnyObject)["option_name"] as! String)
let prices = ((((aryDictData["options"]! as AnyObject)! as AnyObject) 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
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>尽量避免单元格中的 for 循环,在构建数据源时,您可以创建这些选项名称并将其存储在带有一些键的数组中,然后每次在 cellforrow 中重用该键,而不是再次创建 n再次。</p>
<pre><code>for i in 0..<((aryDictData["options"]! as AnyObject)! as AnyObject).count {
let optionName = ((((aryDictData["options"]! as AnyObject)
! as AnyObject) as AnyObject)["option_name"] as!
String)
let prices = ((((aryDictData["options"]! as AnyObject)
! as AnyObject) as AnyObject)["price"] as! String)
aryOptionName.append("\(optionName) ($\(prices))")
}
strOptionName = aryOptionName.joined(separator: "\n")
cell.lblOptionNames.text = strOptionName
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在表格 View 中向上滚动时 UITableViewCell 为空,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46216360/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46216360/
</a>
</p>
页:
[1]