Merge pull request #1882 from AlphaWallet/fix-token-cards-screen-cards-displaying-info-from-wrong-cards

Fix: cards in token cards screen display information from wrong cards if there are many cards (10-ish), after scrolling
pull/1824/head
James Sangalli 4 years ago committed by GitHub
commit 854b65ddf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift

@ -34,6 +34,9 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
private let roundedBackground = RoundedBackground()
private let tableView = UITableView(frame: .zero, style: .plain)
private let buttonsBar = ButtonsBar(numberOfButtons: 3)
//TODO this wouldn't scale if there are many cells
//Cache the cells used by position so we aren't dequeuing the standard UITableView way. This is so the webviews load the correct values, especially when scrolling
private var cells = [Int: TokenCardTableViewCellWithCheckbox]()
private var isMultipleSelectionMode = false {
didSet {
if isMultipleSelectionMode {
@ -356,6 +359,10 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
cell.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressedTokenInstanceIconified)))
}
}
private func reusableCell(forRowAt row: Int) -> TokenCardTableViewCellWithCheckbox {
cells[row, default: TokenCardTableViewCellWithCheckbox(frame: .zero)]
}
}
extension TokensCardViewController: VerifiableStatusViewController {
@ -389,7 +396,7 @@ extension TokensCardViewController: UITableViewDelegate, UITableViewDataSource {
}
let tokenType = OpenSeaBackedNonFungibleTokenHandling(token: tokenObject, assetDefinitionStore: assetDefinitionStore, tokenViewType: .viewIconified)
let cell = tableView.dequeueReusableCell(withIdentifier: TokenCardTableViewCellWithCheckbox.identifier, for: indexPath) as! TokenCardTableViewCellWithCheckbox
let cell = reusableCell(forRowAt: indexPath.row)
var rowView: TokenCardRowViewProtocol & UIView
switch tokenType {
case .backedByOpenSea:

Loading…
Cancel
Save