Search code examples
iosnslayoutconstraintxcode-storyboard

Cells disappearing in static table when working with keyboard before displaying whole table


I have created one larger static table using a storyboard (can't fit to an iPhone 6 display). Static table in the storyboard.

It is displayed correctly only when I scroll all the way through the table. Problem occurs when I open any keyboard before scrolling through the table (keyboard editing text field), than some of my cells disappear. Cells disappeared. They appear only when I scroll back up and down again.

Any suggestions on what is wrong?

[UDPATE] I tried to recreate the problem and it appears that the problem is caused by constraints. When I add classic UITextField it works just fine, but when I add ANY constraints, it behaves exactly like described above.


Solution

  • Solution for this problem is to call setNeedsUpdateConstraints on every disappearing cell everytime UITextField Editing Did End.

    // example code
    @IBAction func textFieldEndEditing(_ sender: UITextField) {
        for cell in brokenConstraintsCells {
            cell.setNeedsUpdateConstraints()
        }
    }