UITableViewCell 上的倒数计时器,UITableView 的 Scrolling/laggy 问题
Countdown timer on UITableViewCell, Scrolling/laggy issue of UITableView
根据我的标题,我有 Table 视图,每行显示彩票,每张彩票都有其详细信息视图。彩票有自己的开奖时间。
动态门票显示在 table 视图中,现在考虑 table 上的 10 到 15 张门票。第一次一切都运作良好。
但是当我上下滚动 table 5 到 6 次或详细查看票证 5 到 6 次时,table 挂起。
问题只是 NSTimer,我每秒重复一次计时器。当我被移除计时器时, table 没有被绞死。
我也尝试通过以下代码删除单元格的可重用性,但对我不起作用。
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; // I know it's bad for us. :(
在创建 timer
之前,我还 isValid
和 nil
有人遇到过这样的问题,或者有人可以给我建议来解决我的问题吗?
花了 11 个小时后,我找到了适合我的解决方案。早些时候我在做什么?我为每个 row/ticket 和 repeats:YES
创建了计时器,因此计时器方法将每 1 分钟连续调用一次。那就是问题发生的方式。
我删除了每一行的每个计时器的逻辑,并将单个计时器放在 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
}
}
希望以上逻辑适用于像我一样遇到同样问题的人。
根据我的标题,我有 Table 视图,每行显示彩票,每张彩票都有其详细信息视图。彩票有自己的开奖时间。 动态门票显示在 table 视图中,现在考虑 table 上的 10 到 15 张门票。第一次一切都运作良好。
但是当我上下滚动 table 5 到 6 次或详细查看票证 5 到 6 次时,table 挂起。 问题只是 NSTimer,我每秒重复一次计时器。当我被移除计时器时, table 没有被绞死。 我也尝试通过以下代码删除单元格的可重用性,但对我不起作用。
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; // I know it's bad for us. :(
在创建 timer
之前,我还 isValid
和 nil
有人遇到过这样的问题,或者有人可以给我建议来解决我的问题吗?
花了 11 个小时后,我找到了适合我的解决方案。早些时候我在做什么?我为每个 row/ticket 和 repeats:YES
创建了计时器,因此计时器方法将每 1 分钟连续调用一次。那就是问题发生的方式。
我删除了每一行的每个计时器的逻辑,并将单个计时器放在 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
}
}
希望以上逻辑适用于像我一样遇到同样问题的人。