對不起,我知道這是一個重複問題,但我無法理解其他問題的答案。斯威夫特3滾動自定義單元格更改
我的自定義單元正在更改滾動。我知道這是由於重用標識符,但我不知道如何解決它。任何幫助,將不勝感激。我也使用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,如果不是則顯示出圖像)
你爲什麼在每一個設置pok1 if hidden = flase?不應該是你設置圖像的口袋妖怪? –
我犯了一個菜鳥錯誤,沒有改變if語句中的正確值! Whoopsie – mint
是的,修復它!我的臉是紅的,謝謝aha – mint