A timer was used in the previous project. It was thought to be very simple. It was finished with a timer and later found that it was not that simple.
Timer may be blocked, leading to inaccurate timing. The delay is still justified. The key is that the events are indeed getting faster and faster. for sellers who promote the second-level ranking, the events have not arrived yet, everything was taken away.
Later, I used a lot of methods to solve the timing problem perfectly. After checking the information, I finally came up with a better solution:
__block TestViewController *blockSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
blockSelf->_timer=[NSTimer scheduledTimerWithTimeInterval:1.0
target:blockSelf
selector:@selector(caculateLeftTimeForTomorrow)
userInfo:nil
repeats:YES] ;
[[NSRunLoop currentRunLoop] addTimer:blockSelf->_timer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
});
Only a queue is added on the basis of the original and timer is started in backgroud. In this way, the blocking problem is basically solved. (because the block references the self parameter, the self is retain and the page cannot be released. Therefore, _ block converts self to a local variable)