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:
parent
ca61e09536
commit
cbc602245e
|
@ -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()
|
||||
|
|
|
@ -33,7 +33,6 @@ class TunnelDetailTableViewController: UITableViewController {
|
|||
private var peerFieldIsVisible = [[Bool]]()
|
||||
|
||||
private weak var statusCell: SwitchCell?
|
||||
private var onDemandStatusObservationToken: AnyObject?
|
||||
private var statusObservationToken: AnyObject?
|
||||
private var reloadRuntimeConfigurationTimer: Timer?
|
||||
|
||||
|
@ -352,7 +351,7 @@ extension TunnelDetailTableViewController {
|
|||
let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath)
|
||||
cell.key = tr("tunnelOnDemandKey")
|
||||
cell.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting)
|
||||
onDemandStatusObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak cell] tunnel, _ in
|
||||
cell.observationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak cell] tunnel, _ in
|
||||
cell?.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting)
|
||||
}
|
||||
return cell
|
||||
|
|
Loading…
Reference in New Issue