I'm having al lot of troubles when I have updated Xcode from 12 to 13.
**All the table view controllers are not yet working as before.**
Doing dome debug I have noticed that when the command: tableView.dequeueReusableCell is used to read the already instantiated cells, it get the wrong pointers.
Example, I have 3 cells, and the first time the command dequeueReusableCell create one pointer for each cell (self)
row: 0, cell: <andrea.TestCell: 0x7fc387f19320
row: 1, cell: <andrea.TestCell: 0x7fc388a07730
row: 2, cell: <andrea.TestCell: 0x7fc388a1c230
when I reload the table (to refresh the data), the pointers are swapped
row: 0, cell: <andrea.TestCell: 0x7fc388a1c230
row: 1, cell: <andrea.TestCell: 0x7fc387f19320
row: 2, cell: <andrea.TestCell: 0x7fc388a07730
So, since that I'm using internal class variables (see below cell_store_var), when the table is refresh all the stored variables inside the class are not yet aligned with their right position.
I did a lot of trials but without success, and I don't know how to update by App on Apple Store,
here the xcode project: table view (this is only an example to reproduce the issue)
thanks, Andrea
import UIKit
class ListController_test: UIViewController, UITableViewDataSource, UITableViewDelegate {
var timer_3sec: Timer!
@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
timer_3sec = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(self.read_sensors), userInfo: nil, repeats: true)
}
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TestCell
cell.refresh(index: indexPath.row)
print("Loaded - IndexPathItem: \(indexPath.item), cell: \(cell.self)")
return cell
}
//imposta l'altezza delle celle in modo dinamico in base al tipo di sensore
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
@objc func read_sensors () {
self.tableView.reloadData()
}
}
import UIKit
class TestCell: UITableViewCell {
var cell_store_var : Int = 0
@IBOutlet weak var label: UILabel!
@IBOutlet weak var label2: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func refresh(index:Int) {
cell_store_var = index + cell_store_var + 1
print("index: \(index), cell_store_var: \(cell_store_var)")
let self_address = String(format:"%02X", self.hashValue)
label.text = "index: \(index), cell_store_var: \(cell_store_var)"
label2.text = "pointer: 0x\(self_address)"
}
}