Starting from iOS18 UIHostingController behaves weirdly that it resets the state of the view when you scroll up and down of the UITableView, even though associated UITableViewCell is unique and does reuse
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "SwiftUICell", for: indexPath)
let swiftUIView = SwiftUIView() // A SwiftUI View
cell.contentConfiguration = UIHostingConfiguration { // <- Here is the bug
swiftUIView
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "NormalCell", for: indexPath)
cell.textLabel?.text = items[indexPath.row]
return cell
}
}
Also in iOS18 release notes thee mentioned some fix related to this but looks like issue is not fixed
Please see the attached video