Skip to content

Instantly share code, notes, and snippets.

@hannesoid
hannesoid / iOS15-UITableView-DuplicateCellUseIssue.md
Last active June 22, 2023 14:26
iOS15 UITableView Duplicate Cell Usage Issue

This only happens on iOS 15 and only when building with Xcode 13. UITableView with (non-diffable) UITableViewDataSource and just one cell type.

Steps

The set up where the issues arises is, we have a row in which we are editing text, insert another after it, and want to continue editing in the new row.

  • [row 0] cell_0 with textView that is firstresponder

Then we call insertRows(at: [.init(row: 1, section:0)], with: …). Within UITableViewDataSource.tableView(…, cellForRowAt:) we correctly get tableView do dequeue a new instance cell_1. (side note: all cells have same reuseIdentifier). In the same tableView(…, cellForRowAt:) method we configure the cell's textView to become the new firstResponder.