gpt4 book ai didi

ios - 如何防止 dequeueReusableCellWithIdentifier 重复我的段选择?

转载 作者:行者123 更新时间:2023-11-29 01:00:10 24 4
gpt4 key购买 nike

我的表格包含自定义单元格,其中包含 uisegment问题是,当选择 uisegment 中的任何项目并在表格 View 中向下滚动时,它会更改表格向下单元格中 uisegment 中的选择

几乎单元格1像11,单元格2像12

它与 dequeueReusableCellWithIdentifier 有关,我的问题是解决它的最佳方法是什么?

enter image description here

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

let item = self.cells.items[indexPath.row]

if let cellHedaer: TcPationQuestionHeader = tableView.dequeueReusableCellWithIdentifier("HeaderItem") as? TcPationQuestionHeader {
cellHedaer.setCell(Results.Questions[indexPath.row/2 ])

if item as? SwiftyAccordionCells.HeaderItem != nil {
let cellItem: TcPationQuestionItem = tableView.dequeueReusableCellWithIdentifier("Item") as! TcPationQuestionItem

cellItem.setCell(Results.Questions[indexPath.row/2])

return cellItem
}

cellHedaer.selectionStyle = UITableViewCellSelectionStyle.None
return cellHedaer
}

最佳答案

我在您的代码中发现了 2 个主要问题:

  1. 您不应该将状态保留在 UI 中。每次从 UI 访问数据是个大错误。您应该在模型中保留选择。最简单的方法是将数组变量保存在 Controller 中。

  2. 在某些情况下,您会调用 dequeueReusableCellWithIdentifier 2 次。那也不应该发生。

不要忘记 cellForRow 的实现连接到 numberOfRowsAtIndexPathnumberOfSections。如果您想获得更详细的帮助,请在此处粘贴这两个函数。

关于ios - 如何防止 dequeueReusableCellWithIdentifier 重复我的段选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37104434/

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