iOS: KeyValueCell should hold the observation token

And should nil the token when preparing for reuse.

Otherwise, the observation closure is still active even after the cell
gets reused.

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander
2019-02-03 12:27:51 +05:30
parent ca61e09536
commit cbc602245e
2 changed files with 4 additions and 2 deletions
@@ -71,6 +71,8 @@ class KeyValueCell: UITableViewCell {
var onValueChanged: ((String) -> Void)?
var onValueBeingEdited: ((String) -> Void)?
var observationToken: AnyObject?
private var textFieldValueOnBeginEditing: String = ""
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
@@ -187,6 +189,7 @@ class KeyValueCell: UITableViewCell {
keyboardType = .default
onValueChanged = nil
onValueBeingEdited = nil
observationToken = nil
key = ""
value = ""
configureForContentSize()