ios - Reload data in table view without harming animation -
i have uitableview-based in-game shop.
every cell has "buy" button enabled , can switched "bought" if item one-time purchase or can disabled if there not enough money.
right calling reloaddata
every time buy button being pressed in order update visible cells , current cell itself. (i have update cells, because after purchase possible there wont enough money visible item cells).
but causes weird animation glitches, when click on 1 cell's buy button , animation finishes on one.
i think happens due reusability of cells. want know how reload data in whole table view without harming native animation.
the thing can think of not use reusable cells , cache them all, dont think programming practice.
first, make sure view layer , model layer separate. there should non-view object knows each item; we'll call item
.
now, create itemcell
(you have 1 already). that's reusable cell. hand item
. should configure based on data in there.
use kvo, delegation, or notifications let cell observe item. when item
changes status, cell should update own button.
when cell reused, you'll pass new item
it. should stop observing previous one, , start observing new 1 (and of course reconfigure match current status).
by separating views (which reusable , transitory) model (which stable , long-lived), performance benefits of cell reuse correct animations , no need call reloaddata
.
Comments
Post a Comment