Countdown timer on UITableViewCell, Scrolling/lagg

2019-09-17 08:25发布

问题:

As per my title, I have Table view which display lottery tickets in each row and each ticket has it's detail view. Ticket has it's own time for draw. Dynamic tickets are display on table view, right now consider 10 to 15 tickets on the table. First time all are working well.

But when I scroll table 5 to 6 times up and down OR go in detail of ticket 5 to 6 times then table hang. Issue is only NSTimer, I repeat timer for every second. When I was removed timer then table was not hanged. I also try to remove reusability of cell by following code, but didn't work me.

NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; // I know it's bad for us. :(

I also isValid and nil before create timer Anybody had fetched issue like this or can anybody give me suggestion for solve my problem ?

回答1:

After spend 11 hours, I found solution for me. earlier what I was doing ? I was created timer for each row/ticket with repeats:YES so method of timers will call continuously every 1 minute. Thats way problem was occurred.

I removed logic of each timer for each row and put single timer in viewWillAppear (Or whatever you want to put) method apply repeats:YES and use my below logic in the method of timer

- (void) calculateTimer
{
    // Here count down timer is only for visible rows not for each rows.

    NSArray *listOFCurrentCell = [myTableView visibleCells]; // Returns the table cells that are visible in the table view.
    for(customCell *theMycustomCell in listOFCurrentCell)
    {
        => Here I put logic of count down timer
        => It's will be only for those row that display currently 
    }
}

Hope that above logic use for those people which get same issue like me.