문제

I have this timer

NSTimer *timer;
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                     target:self selector:@selector(updateCounter:)
                                   userInfo:_TimeLabel.text repeats:YES];

in what event should I add the code

 [timer invalidate];

if I want to stop this timer if I change views? e.g from tableviewcontroller to detailviewcontroller?

도움이 되었습니까?

해결책

Your view controller has a number of methods that you can override to interact with its view being shown and hidden, use now of those:

  1. viewWillDisappear:
  2. viewDidDisappear:

(Be sure to call super as part of your implementation)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top