开发者

UITableView cell reuse causing NSTimer problems

I have a UITableView with a custom cell I built. The cell has several labels, a start button and a stop button, and an NS开发者_运维问答Timer that gets fired off and stopped from the buttons.

The labels display data from sqllite (through core data) and the timer runs individually for each separate cell.

This all works fine until I have more cells and cell reuse gets triggered. At that point, each cell shows the correct data in its labels, but if I start a timer for the first cell, the moment it rolls off screen, the next cell showing (and subsequently reusing the previous cell) will have its timer going as well.

I can't figure out how to guarantee each cell has its own timer thread with cell reuse.

Any help would be appreciated.


In your case the cells have internal state (timer). When cell is reused, it's state is lost (or even worth reused cell will inherit previous state). You have two options

  • don't reuse cells
  • make cells stateless (e.g. move your timers to controller)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜