[英]How do I stop timer on view transition?
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? 如果要更改视图是否要停止此计时器? eg from tableviewcontroller to detailviewcontroller?
例如从tableviewcontroller到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: 您的视图控制器具有许多方法,您可以重写这些方法来与正在显示和隐藏的视图进行交互,现在使用这些方法:
viewWillDisappear:
viewDidDisappear:
(Be sure to call super
as part of your implementation) (确保将
super
称为实现的一部分)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.