我有一个包含3个部分的表视图。 在最后一节我有两个单元格。 不,当我点击最后一个单元格(Segue到ViewController)并返回到tableView时,我的最后一个单元格与前一个单元格完全相同(第2行第0行)。当我关闭应用程序并返回到表时,一切正常。 我搜索过很多但却一无所获。
这是我的代码:
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
}
答案 0 :(得分:0)
问题可能是你在代码开头打开单元格:
让cell2:SecondTwoWayCellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier(" SecondTwoWayCell")as!SecondTwoWayCellTableViewCell
你做了if if check to things ...但你不清理单元格并记住你正在重用一个带有标识符的单元格... 所以,你需要做的只是在你通过放置像:
之类的东西来清除单元格之后清除单元格cell2 = SecondTwoWayCellTableViewCell()
然后"如果indexPath.row == 0&& DoubleMatchIdentifierHome [4]!="" {"
因此,如果单元格不属于任何if,则单元格始终为标准值。