index path update

This commit is contained in:
Pfeil, Scott Robert 2020-03-09 11:29:35 -04:00
parent e48a0e3af9
commit c96e2fa3c2
3 changed files with 22 additions and 7 deletions

View File

@ -31,9 +31,10 @@ extension MFViewController: MoleculeDelegateProtocol {
return nil
}
@objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { }
// These are required because swift will call the extension function otherwise.
@objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) {}
@objc public func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { }
@objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { }
@objc public func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {}
@objc public func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) {}
@objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {}
}

View File

@ -20,6 +20,8 @@ public protocol MoleculeDelegateProtocol {
/// Asks the delegate to add or remove molecules.
//optional
func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation)
func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation)
func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation)
//optional
@ -36,6 +38,10 @@ extension MoleculeDelegateProtocol {
// Do nothing
}
public func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) {
// Do nothing
}
public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
// Do nothing
}

View File

@ -178,8 +178,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
}
}
open override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
open override func addMolecules(_ molecules: [[AnyHashable : Any]], indexPath: IndexPath, animation: UITableView.RowAnimation) {
var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]()
molecules.forEach { molecule in
@ -189,7 +188,6 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
}
DispatchQueue.main.async {
guard let indexPath = self.tableView?.indexPath(for: sender) else { return }
var indexPaths: [IndexPath] = []
for molecule in tmpMolecules {
@ -207,6 +205,16 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
}
}
open override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
DispatchQueue.main.async { [weak self] in
guard let indexPath = self?.tableView?.indexPath(for: sender) else { return }
DispatchQueue.global().async {
self?.addMolecules(molecules, indexPath: indexPath, animation: animation)
}
}
}
open override func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
var tmpMolecules = [ListItemModelProtocol & MoleculeModelProtocol]()