I'm using https://github.com/mineschan/MZTimerLabel/ and in my Tableview cellForRowAtIndex using the timer like below:
UILabel *lblTimer=(UILabel *)[cell viewWithTag:10];
MZTimerLabel *UpgradeTimer = [[MZTimerLabel alloc] initWithLabel:lblTimer andTimerType:MZTimerLabelTypeTimer];
[UpgradeTimer setCountDownTime:timestamp];
[UpgradeTimer startWithEndingBlock:^(NSTimeInterval timestamp) {
lblTimer.text = @"✔";
}];
But after any table reloading or scrolling, the timer behaves strange and seems it re-generates multiple timers for counting in the same place. How should I fix this while using this timer?
Appreciate any help,
Elias
I had a look at
MZTimerLabel
, and it violates MVC badly. It puts something that belongs into the model (the timer that count's down the time) into the view. That is where your problem comes from. Views should be able to be recreated without having side effects on the model.I would recommend to ditch that class, and create your own. It's actually quite easy to achieve something like this.
That's basically all the code you need for a basic countdown in a table. Because it does not store any data in the view you can scroll as much as you like: