gpt4 book ai didi

swift - UITableView 上一节中重复的单元格

转载 作者:行者123 更新时间:2023-11-30 14:00:23 25 4
gpt4 key购买 nike

我有一个包含 3 个部分的表格 View 。在最后一部分中,我有两个单元格。不,当我单击最后一个单元格(转到 ViewController)并返回到 tableView 时,我的最后一个单元格与前一个单元格完全相同(第 2 部分第 0 行)。当我关闭应用程序并返回 tableView 时,一切正常。我搜索了很多,但没有发现任何相关内容。

这是我的代码:

else if indexPath.section == 2 {

let cell2:SecondTwoWayCellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("SecondTwoWayCell") as!SecondTwoWayCellTableViewCell



if indexPath.row == 0 && DoubleMatchIdentifierHome[4] != "" {



let currentPlayerHome1 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierHome[4]) as! Player
let currentPlayerHome2 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierHome[5]) as! Player

let currentPlayerAway1 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierAway[4]) as! Player
let currentPlayerAway2 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierAway[5]) as! Player


cell2.identifierPlayerHome1.text = DoubleMatchIdentifierHome[4]
cell2.playerHome1.text = currentPlayerHome1.name!
cell2.identifierPlayerHome2.text = DoubleMatchIdentifierHome[5]
cell2.playerHome2.text = currentPlayerHome2.name!

cell2.identifierPlayerAway1.text = DoubleMatchIdentifierAway[4]
cell2.playerAway1.text = currentPlayerAway1.name!
cell2.identifierPlayerAway2.text = DoubleMatchIdentifierAway[5]
cell2.playerAway2.text = currentPlayerAway2.name!

cell2.score.text = ("\(matches[18].scoreHome!):\(matches[18].scoreAway!)")

return cell2
}

else if indexPath.row == 1 && DoubleMatchIdentifierHome[6] != "" {




let currentPlayerHome1 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierHome[6]) as! Player
let currentPlayerHome2 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierHome[7]) as! Player

let currentPlayerAway1 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierAway[6]) as! Player
let currentPlayerAway2 = CoreDataManager.defaultListener().getPlayer(date, identifier: DoubleMatchIdentifierAway[7]) as! Player




cell2.identifierPlayerHome1.text = DoubleMatchIdentifierHome[6]
cell2.playerHome1.text = currentPlayerHome1.name!
cell2.identifierPlayerHome2.text = DoubleMatchIdentifierHome[7]
cell2.playerHome2.text = currentPlayerHome2.name!

cell2.identifierPlayerAway1.text = DoubleMatchIdentifierAway[6]
cell2.playerAway1.text = currentPlayerAway1.name!
cell2.identifierPlayerAway2.text = DoubleMatchIdentifierAway[7]
cell2.playerAway2.text = currentPlayerAway2.name!

cell2.score.text = ("\(matches[19].scoreHome!):\(matches[19].scoreAway!)")

return cell2

}

return cell2






}

最佳答案

问题可能是您在代码开头打开单元格,方法是:

let cell2:SecondTwoWayCellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("SecondTwoWayCell") as!SecondTwoWayCellTableViewCell

您执行 if 来检查事物...但您没有清理单元格并记住您正在重复使用带有标识符的单元格...因此,您需要做的只是在将单元格出队后清除单元格,方法如下:

cell2 = SecondTwoWayCellTableViewCell()

然后是“if indexPath.row == 0 && DoubleMatchIdentifierHome[4] != ""{"

因此,单元格始终会达到标准值,以防它不符合任何 if 条件。

关于swift - UITableView 上一节中重复的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33068631/

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