Why the show/ hide table view mechanism doesn't work in non iPhone SE simulator?

I am using the following mechanism, to perform UITableView's row show and hide.

class TableViewController: UITableViewController {

    private var hiddenIndexPaths : Set<IndexPath> = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    @IBAction func toggle(_ sender: UISwitch) {
        if sender.isOn {
            show(1)
            show(2)
        } else {
            hide(1)
            hide(2)
        }
    
        tableView.beginUpdates()
        tableView.endUpdates()
    }
    
    private func isHidden(_ indexPath: IndexPath) -> Bool {
        hiddenIndexPaths.contains(indexPath)
    }
    
    private func hide(_ item: Int) {
        hiddenIndexPaths.insert(IndexPath(item: item, section: 0))
    }
    
    private func show(_ item: Int) {
        hiddenIndexPaths.remove(IndexPath(item: item, section: 0))
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if isHidden(indexPath) {
            return 0.0
        }
        
        return super.tableView(tableView, heightForRowAt: indexPath)
    }
}

As you can see, it works great in iPhone SE simulator (Works well in iPhone SE real device too)

iPhone SE simulator

linkText

However, in non iPhone SE simulator (Like iPhone 13), once the table row is hidden, it can no longer be shown. Please refer to the following video.

iPhone 13 simulator

I am not sure what will its behavior in iPhone 13 real device, because I do not have access.

I was wondering, do you have any idea why such issue occurs? If you are interested to test, here's the complete workable sample - https://github.com/yccheok/show-hide-table-row-bug

For additional information,

Testing environment

  1. XCode Version 14.0 (14A309)
  2. macOS Monterey Version 12.6 (M1)
  3. Simulator iPhone 13, iOS 15

You're running the same code on an iPhone SE with iOS 16, and an iPhone 13 with iOS 15 - so, two variables to check.

Does it work on other iOS 16 simulators? If so, it looks like the code doesn't work on iOS 15, and you need to determine why. Are you using something that isn't supported in iOS 15?

Right, I've tried your code on an iPhone 13 Pro Max with both iOS 16 and iOS 15.5, and an iPhone 13 with iOS 15.5 (those are the simulators I have). It works in all three cases.

Try to change as this, at least to test :

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if isHidden(indexPath) {
            return 0.0
        } else {
            return 20.0
        }
        
        // return super.tableView(tableView, heightForRowAt: indexPath)
    }
Why the show/ hide table view mechanism doesn't work in non iPhone SE simulator?
 
 
Q