UITableViewをスクロールしている時にNSTimerが呼ばれない
UITableViewに限らずUIScrollViewを継承しているクラス全部に言えることだと思うが
以下のような処理だとスクロール中にタイマー処理がスキップされる
- (void)setupTimer { NSTimer *timer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES]; } - (void)timerUpdate { NSLog(@"timer呼ばれた"); }
改善コード
mainRunLoopにタイマーを追加してやれば良い
- (void)setupTimer { NSTimer *timer = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(timerUpdate) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes]; } - (void)timerUpdate { NSLog(@"timer呼ばれた"); }