【发布时间】:2014-08-25 12:10:43
【问题描述】:
在我的应用程序中,当我从一个视图控制器移动到另一个视图控制器时,我需要释放我的 NSTimer。如何在 ARC 中释放这种类型的对象?我正在使用下面的代码来创建和发布NSTimer,但是我必须在视图控制器中在哪里编写这个发布代码?
为了创造。
- (void)viewDidLoad{
[super viewDidLoad];
updateBCK = [NSTimer scheduledTimerWithTimeInterval:(5.0) target:self selector:@selector(changeImage) userInfo:nil repeats:YES];
[updateBCK fire];
}
-(void)changeImage{
static int i=0;
if (i == [myImages count]){
i=0;
}
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:0.6];
mainBackgroundImageView.alpha=1;
mainBackgroundImageView.image =[myImages objectAtIndex:i];
NSLog(@"\n The main screen image is %@",[myImages objectAtIndex:i]);
[UIImageView commitAnimations];
i++;
}
用于发布。
[updateBCK invalidate];//
updateBCK = nil;
提前致谢。
【问题讨论】:
-
推动新视图控制器的代码在哪里
-
我正在使用 Timer 在 First View 控制器中随机显示背景图像。
-
你说当你切换到另一个视图控制器时你想关闭定时器是不是正确的???贴出那部分代码
-
我正在使用图像数组在我的第一个视图控制器中随机显示,并在第一个视图控制器中的按钮上创建,当我按下按钮时,我需要转到第二个视图控制器,我也有在第一个视图控制器中停止计时器。