暂停 NSTimer 以浏览屏幕
我有一个幻灯片,每 3 秒调用一次 NSTimer
函数,并且当用户触摸该按钮时,我有一个“关于”按钮,该按钮会转到另一个屏幕:
-(IBAction)toAbout:(id)sender
{
about *ab=[[about alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:ab animated:YES];
[ab release];
}
并使用此函数从“关于”屏幕返回,
-(IBAction)aboutButton:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
为什么我可以暂停 < code>NSTimer 当我转到关于屏幕时? 为什么我可以创建在幻灯片屏幕中工作并且在关于屏幕中也工作的对象?
i have a slideshow that works with NSTimer
function calls every 3 seconds and i have a About button when user touch about that goes to another screen:
-(IBAction)toAbout:(id)sender
{
about *ab=[[about alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:ab animated:YES];
[ab release];
}
and returns from about screen with this function
-(IBAction)aboutButton:(id)sender
{
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
why I can pause the NSTimer
when I'm go to about screen?
and why I can creat the object that works in slideshow screen and works in about screen too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有暂停计时器的方法,并且调用
[timer setFireData:[NSDate distanceFuture]]
没有意义。相反,进入第一个视图后,使计时器无效并创建一个新计时器。通过说
[timer invalidate];
来使计时器无效,并将计时器设置为 niltimer = nil;
。There is no method for pausing your timer and it doesn't make sense to call
[timer setFireData:[NSDate distantFuture]]
. Instead, invalidate the timer and create a new one once entering the first view.Invalidate by saying
[timer invalidate];
and set the timer to niltimer = nil;
.要暂停计时器,您可以简单地调用
这不会使计时器无效,而只是避免计时器继续触发。
To pause the timer you may simply call
This does not invalidate the timer but simply avoid that the timer keeps firing.