简体   繁体   English

UITableViewCell上的倒数计时器,UITableView的滚动/延迟问题

[英]Countdown timer on UITableViewCell, Scrolling/laggy issue of UITableView

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. 动态票证显示在表视图上,现在考虑表上有10到15张票证。 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. 但是,当我上下滚动表5至6次或详细查看票证5至6次时,表就会挂起。 Issue is only NSTimer, I repeat timer for every second. 问题只是NSTimer,我每秒重复计时器。 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 ? 在创建timer之前,我也是isValidnil有人曾经这样抓过问题,或者有人可以给我建议解决我的问题吗?

After spend 11 hours, I found solution for me. 花了11个小时后,我找到了解决方案。 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. 我为每个行/票创建了带有repeats:YES的计时器repeats:YES所以计时器方法将每1分钟连续调用一次。 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 我删除了每一行的每个计时器的逻辑,并将单个计时器放在viewWillAppear (或您想要放置的任何东西)方法中应用repeats:YES并在计时器方法中使用以下逻辑

- (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. 希望以上逻辑对像我这样遇到同样问题的人们有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM