S
S
Stanislav Korolevskiy2017-09-11 20:49:46
Swift
Stanislav Korolevskiy, 2017-09-11 20:49:46

How to reload accessoryType icons in UITableViewController cells?

Tell me please. In the cellForRowAt method, I wrote an icon in a cell with an inline purchase.

if indexPath.row == 1 {
            if isPurchase {
                cell.accessoryType = .disclosureIndicator
            } else {
                let iconLockDisclosureIndicator = UIImage(named: "icon_settings.png")
                cell.accessoryView = UIImageView(image: iconLockDisclosureIndicator)
            }
        }

If the user has not made a purchase, then the corresponding icon is displayed in the cell. After a successful purchase, the icon should change to the standard one. How to force the table to reload and update the icons? The reloadData() method doesn't help. Everything works only after restarting the application.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Korolevskiy, 2017-09-11
@korolevsky_s

Wrote such a function. I run it in the method with the purchase.

func reloadCell() {
        let indexPath = IndexPath(item: 1, section: 0)
        tableView.cellForRow(at: indexPath)?.accessoryType = .disclosureIndicator
        tableView.reloadRows(at: [indexPath], with: .automatic)
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question