ios - NSTimer not working well for UITableviewCell -
I have to create something like this, there is a UTIB VUI that has many lines with multiple sections and different timers Let's show 'Hh: mm: ss' format and like this countdown, every second is decreasing.
I am having problems that when I scroll UITable VU, some UILBs are initialized again And the time of countdown takes place and even There are more rides for some cells. I am using the following code to get my requirement:
- (UITableViewCell *) TableView: (UITableView *) Table View CellForouaitindPath: (NSIndexPath *) indexPath {// somewhere , In this method elapseedTimeTimer = [NSTM Scheduled Timer with Time Interval: 1.0 Target: Self Selector: @Selector (Movable Timer :) User Ink: DIC Repeats: Yes]; [[NSRunLoop currentRunLoop] addTimer: elapsedTimeTimer forMode: NSRunLoopCommonModes]; } - (zero) running timer: (nstimer *) timer {secondsLeft -; // I am able to get seconds of seconds = seconds / 3600; Min = (secondslift% 3600) / 60; Secs = (secondslift% 3600)% 60; Cell.lblTime.text = [NSString stringWithFormat: @ "% 02d:% 02d:% 02d", hours, minutes, seconds]; } Please help me to solve this problem. Any help, definitely will appreciate.
Thank you
You need an array of elements or dictionary of your timer To keep track
Each cell is reused in the utivhetive and since your timers will be affected. Instead of
ElapsedTimeTimers [indexPath.row] elapsedTimeTimer where elapsedTimeTimers is the timer array.
Of course, if you have a section, then this applies. If you have more then you have to calculate the correct index. Also, if you have an object to keep this data, you can use the object ID or something like this.
Comments
Post a Comment