Junior — Middle
Kuidas tagada tabeli lahtrite korduvkasutus ressurside optimeerimiseks?
sobes.tech AI
Vastus AI-lt
In iOS, the mechanism for reusing cells in a table uses cell reuse identifiers.
Main steps:
- Register the cell class or nib with a unique identifier.
- In the
tableView(_:cellForRowAt:)method, calldequeueReusableCell(withIdentifier:)to get a reusable cell. - Configure the cell with the current data.
This allows not to create a new cell for each row, but to reuse existing ones, saving memory and improving performance.
Example in Swift:
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
cell.textLabel?.text = data[indexPath.row]
return cell
This way, the system manages a pool of cells and reuses them as the table scrolls.