gpt4 book ai didi

ios - 防止在表格 View Swift 中重用自定义单元格

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:44 26 4
gpt4 key购买 nike

我有一个问题,我不确定如何解决。

我有两个自定义单元格 Nib - 两者的数据都是从单独的数组中获取的。

结构如下

nib1-cell line1
nib1-cell line2
...
nib1-cell line n
nib2-cell line1

uibutton 的最后总是有一个 nib2-cell。
一旦 uibutton 被按下 - nib1 数组被附加。
我想出了一种方法如何在 tableview 的底部插入值,但是当我向下或向上滚动时,带有 nib2 的单元格被重新使用并替换为 nib1-cell 数据。 enter image description here

我怎样才能防止这些单元格被重复使用或保存它们的状态?

谢谢。

更新:数据源和 cellForRowAtIndexPath 代码

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return someTagsArray.count

}

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

if(indexPath.row < someTagsArray.count - 1){
var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell

cell.lblCarName.text = someTagsArray[indexPath.row]


return cell

} else if (indexPath.row == someTagsArray.count - 1){
var celle:vwAnswers = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! vwAnswers
celle.Answer1.setTitle(answersdict[answersdict.endIndex - 2], forState:UIControlState.Normal)

answertitle1 = "\(celle.Answer1.currentTitle!)"

celle.Answer2.setTitle(answersdict.last, forState:UIControlState.Normal)
answertitle2 = "\(celle.Answer2.currentTitle!)"

//println(answertitle2)

return celle

} else {
var cell2:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
return cell2
}

}

最佳答案

您必须在 cellForRowAtIndexPath 中确定所需的单元格类型,并将正确的可重用单元格出队。可能类似于 if (indexPath.row + 1)%3 == 0 然后出列一个应答单元格。

但是,您可能希望为此使用节标题。如果没有看到您如何实现数据源,很难说。

关于ios - 防止在表格 View Swift 中重用自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32258952/

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