From 52e8ce7621f5a46c63b3832b0ca6da056cc33a90 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Thu, 16 May 2024 10:20:31 -0400 Subject: [PATCH] Digital PCT265 story PCT-135: Prevent registering table cells on ListViewTemplate handleNewData when the page is not changing. --- .../Atomic/Templates/MoleculeListTemplate.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index ad908568..ef382c0f 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -19,7 +19,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol public var moleculesInfo: [MoleculeInfo]? var observer: NSKeyValueObservation? - + //-------------------------------------------------- // MARK: - Computed Properties //-------------------------------------------------- @@ -87,8 +87,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol open override func handleNewData(_ pageModel: PageModelProtocol? = nil) { super.handleNewData(pageModel) - setup() - registerWithTable() + + if pageModel != nil { + setup() + registerWithTable() + } } open override func updateUI(for molecules: [MoleculeModelProtocol]? = nil) { @@ -368,7 +371,7 @@ extension MoleculeListTemplate: MoleculeListProtocol { let removeIndex = indexPath.row - index moleculesInfo?.remove(at: removeIndex) } - + guard let animation = animation, indexPaths.count > 0 else { return } tableView?.deleteRows(at: indexPaths, with: animation) @@ -378,7 +381,7 @@ extension MoleculeListTemplate: MoleculeListProtocol { public func addMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], indexPath: IndexPath, animation: UITableView.RowAnimation?) { var indexPaths: [IndexPath] = [] - + for molecule in molecules { if let info = self.createMoleculeInfo(with: molecule) { self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier) @@ -387,7 +390,7 @@ extension MoleculeListTemplate: MoleculeListProtocol { indexPaths.append(IndexPath(row: index, section: 0)) } } - + guard let animation = animation, indexPaths.count > 0 else { return } self.tableView?.insertRows(at: indexPaths, with: animation)