Objective c ViewController中的暂停和恢复计时器
我想暂停并恢复viewcontroller中的计时器,它在mainviewcontroller中显示为子视图。按下mainviewcontroller中的“播放/暂停”按钮时,它将视图控制器显示为子视图,并播放音频 在视图控制器中设置此NSTimerObjective c ViewController中的暂停和恢复计时器,objective-c,cocoa-touch,ios6,Objective C,Cocoa Touch,Ios6,我想暂停并恢复viewcontroller中的计时器,它在mainviewcontroller中显示为子视图。按下mainviewcontroller中的“播放/暂停”按钮时,它将视图控制器显示为子视图,并播放音频 在视图控制器中设置此NSTimer [NSTimer scheduledTimerWithTimeInterval:2.6 target:self sel
[NSTimer scheduledTimerWithTimeInterval:2.6
target:self
selector:@selector(updateView:)
userInfo:nil
repeats:YES];
- (void)updateView:(NSTimer *)theTimer
{
if (index < [textArray count])
{
self.textView.text = [self.textArray objectAtIndex:index];
self.imageView.image = [self.imagesArray objectAtIndex:index];
index++;
} else {
index = 0;
}
[NSTimer scheduledTimerWithTimeInterval:2.6
目标:自我
选择器:@选择器(更新视图:)
用户信息:无
重复:是];
-(void)updateView:(NSTimer*)计时器
{
如果(索引<[textArray count])
{
self.textView.text=[self.textArray objectAtIndex:index];
self.imageView.image=[self.imagesArray objectAtIndex:index];
索引++;
}否则{
指数=0;
}
当按下mainviewcontroller中的播放/暂停按钮时,我想暂停并恢复计时器。我该怎么做
NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval:2.6
target:self
selector:@selector(updateView:)
userInfo:nil
repeats:YES];
[myTimer invalidate];
/*
阻止接收器再次触发,并请求将其从运行循环中移除。
*/
/*
您可以使用此方法在不中断其常规启动计划的情况下启动重复计时器。如果计时器不重复,则即使其计划的启动日期尚未到达,也会在启动后自动使其无效。
*/
/*
阻止接收器再次触发,并请求将其从运行循环中移除。
*/
/*
您可以使用此方法在不中断其常规启动计划的情况下启动重复计时器。如果计时器不重复,则即使其计划的启动日期尚未到达,也会在启动后自动使其无效。
*/首先,您必须在接口文件中保留计时器的引用:
NSTimer *myTimer;
在实现文件中,您可以简单地连接并引用它:
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.6
target:self
selector:@selector(updateView:)
userInfo:nil
repeats:YES];
要停止计时器调用,请执行以下操作:
[myTimer invalidate];
要重新启动,请执行以下操作:
[myTimer fire];
有关NSTimer类的更多信息,请参阅。首先,必须在接口文件中保留计时器的引用:
NSTimer *myTimer;
在实现文件中,您可以简单地连接并引用它:
myTimer = [NSTimer scheduledTimerWithTimeInterval:2.6
target:self
selector:@selector(updateView:)
userInfo:nil
repeats:YES];
要停止计时器调用,请执行以下操作:
[myTimer invalidate];
要重新启动,请执行以下操作:
[myTimer fire];
有关NSTimer类的更多信息,请参阅。谢谢您的回复,但我想通过播放/暂停按钮暂停并恢复它,在我的播放暂停按钮方法中,我确实有暂停计时器和恢复计时器,但它不工作,因为我在mainviewcontroller中还有一个计时器将viewcontroller显示为子视图。我认为这不重要-播放或暂停任何NSTimer的方法只是在像NSTimer*myTimer=[NSTimer scheduledTimerWithTimeInterval…]。如果要在类中使用此指针,则需要将其保存在类的成员变量中。因此,如果我要在Main viewcontroller中的viewcontroller中使用此myTimer来暂停并恢复它。我如何才能在哪个类中创建此计时器?假设您在MyClass中创建它。因此,您应该有一个成员变量m_myTimer和一个公共me方法-(n时间*)getTimer在此类中。mainviewcontroller现在可以通过此方法获取指向计时器的指针…感谢您的回复,但我想通过播放/暂停按钮暂停并恢复它,在我的播放暂停按钮方法中,我有暂停计时器和恢复计时器,但它不工作,因为我在mainviewcontroller中还有一个计时器用于显示viewcont滚动作为子视图我认为这并不重要-播放或暂停任何NSTimer的方法只是在创建指针后像NSTimer*myTimer=[NSTimer scheduledTimerWithTimeInterval…]。如果要在类中使用此指针,则需要将其保存在类的成员变量中。因此,如果我要在Main viewcontroller中的viewcontroller中使用此myTimer来暂停并恢复它。我如何才能在哪个类中创建此计时器?假设您在MyClass中创建它。因此,您应该有一个成员变量m_myTimer和一个公共method-(NSTimer*)getTimer在此类中。mainviewcontroller现在可以通过此方法获取指向计时器的指针。。。