You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have multiple text fields in a table observing changes to a model property, then as the cells are reused they start observing multiple properties. This can be fixed by checking that the observable value returned matches the model property, but it would be better to clear observables when a cell is reused (and as far as I know you can only add obervables).
For the example below, changing pickerTwo value will sometimes also update rowOne as it has previously been observing rowTwo (under cell reuse rules)
case .rowOne:
cell.textField.observe(for: vModel.propertyOne) { (prop1) in
//hack way of ensuring observable is right one (as cannot remove "observe" for cell reuse)
if prop1 == vModel.propertyOne.value {
cell.textField.text = getPropOneValue()
}
}
cell.textField.text = vModel.getPropOneValue()
cell.textField.inputView = pickerOne
case .rowTwo:
cell.textField.observe(for: vModel.propertyTwo) { (prop2) in
if prop2 == vModel.propertyTwo.value {
cell.textField.text = getPropTwoValue()
}
}
cell.textField.text = vModel.getPropTwoValue()
cell.textField.inputView = pickerTwo
The text was updated successfully, but these errors were encountered:
The only way I can see to fix is to either observe everything (rather than bind) and compare index paths, or to override "prepareForReuse" and entirely replace the text field.
Neither is ideal. When I have more time I can look at a "clear all bindings" method that can be applied at start of "cell for index path"
If I have multiple text fields in a table observing changes to a model property, then as the cells are reused they start observing multiple properties. This can be fixed by checking that the observable value returned matches the model property, but it would be better to clear observables when a cell is reused (and as far as I know you can only add obervables).
For the example below, changing pickerTwo value will sometimes also update rowOne as it has previously been observing rowTwo (under cell reuse rules)
The text was updated successfully, but these errors were encountered: