NSTimer 在使用中需要注意的几个问题
NSTimer在UITableViewCell中使用是,需要将timer加到runLoop中。
countDownTimer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(countDown:) userInfo:nil repeats:YES]; NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop]; [currentRunLoop addTimer:countDownTimer forMode:NSRunLoopCommonModes];同一个timer在重复使用之前必需invalidate, 否则会造成之前的timer无法停掉,两个timer同时存在。导致的现象就是timer同时更新两次。
本文介绍了在 iOS 开发中使用 NSTimer 的注意事项,包括如何正确地将 Timer 添加到 RunLoop 中以确保其正常运行,以及在重复使用 Timer 时必须先使其失效以避免出现多个 Timer 同时存在的问题。
149

被折叠的 条评论
为什么被折叠?



