抱歉,我知道这是一个重复的问题,但我无法理解其他问题的答案。
我的自定义单元格在滚动时正在改变。我知道这是由于重用标识符,但我不知道如何解决它。任何帮助,将不胜感激。我也使用indexPath.row来访问数组。
即使我使用重用标识符,如何让我的表格视图不会更改滚动值?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : TeamCell = tableView.dequeueReusableCell(withIdentifier: "TeamCell", for: indexPath) as! TeamCell
cell.trainer.image = UIImage(named: "t\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].imageID)")
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p1.name != 0 {
cell.pokemon1.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p1.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon1.isHidden = true
}
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p2.name != 0 {
cell.pokemon2.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p2.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon2.isHidden = true
}
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p3.name != 0 {
cell.pokemon3.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p3.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon3.isHidden = true
}
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p4.name != 0 {
cell.pokemon4.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p4.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon4.isHidden = true
}
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p5.name != 0 {
cell.pokemon5.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p5.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon5.isHidden = true
}
if Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p6.name != 0 {
cell.pokemon6.image = UIImage(named: "\(Player.User.Gold.trainers[(indexPath as NSIndexPath).row].p6.name)")
cell.pokemon1.isHidden = false
} else {
cell.pokemon6.isHidden = true
}
return cell
}
(该函数只检查数组的值是否为0,如果它不是,则显示图像)
答案 0 :(得分:1)
将您的每个宠物小精灵images
设置为nil
或在placeholder image
单元后立即设置dequeue
,然后将您的每个if-conditions
设置为每个图片视图默认隐藏属性也是如此,如果您的imageview默认隐藏,则在true
条件下设置图像之前将其隐藏属性设置为if
!
答案 1 :(得分:1)
所以评论说这个问题是错误地将pokemon1设置在每个if中。
修改强>
因为我将更加精确地预测: 在每个if条件下,你将pokemon1设置为vissible。你需要使用你的设置作为图像的Pokomen。
有趣的编码