UITableViewCell animations stop when UITableView is scrolling

后端 未结 2 1389
灰色年华
灰色年华 2021-02-10 09:20

I am making an \'event countdown\' scene in my app that uses a UITableViewController to show a list of events that are happening in the future. In each cell I have a countdown t

相关标签:
2条回答
  • 2021-02-10 09:33

    Some more searching on this same issue for UIScrollViews yielded led me to this postMy custom UI elements...

    Basically what is happening is that the NSTimer I was using was not being updated when scrolling because scrolling blocks everything outside of its own run loop mode. The fix is to add the animation NSTimer to the same run loop mode that is used by scrolling: NSRunLoopCommonModes

    Here's how to do it in code:

    NSTimer *timer = [NSTimer timerWithTimeInterval:0.25 self selector:@selector(updateCountdownLabels) userInfo:nil repeats:YES]; 
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
    0 讨论(0)
  • 2021-02-10 09:41

    I am guessing you are using views to store your countdown data. Instead create a model for countdown, it could be initialized with a start date(NSDate) and a duration(NSTimeInterval). Then instead of your views update those Countdown objects according to timer. When a tableview cell becomes visible in the view, it will load data from the corresponding Countdown object and everything should run smoothly.

    0 讨论(0)
提交回复
热议问题