Play和Rewind按钮之间的冲突,用于更新viewcontrollers

时间:2012-03-21 15:38:02

标签: iphone

AVAudioPlayer正在播放音频文件并在点击播放按钮时更新viewcontrollers并且它将在不同的时间间隔加载viewcontrollers,如果在用户点击倒带按钮之间,它会重新开始整个过程​​,但是它之间显示了播放按钮的更新viewcontrollers的流程。如何在用户点击倒带按钮时停止该操作。我想以这样的方式编程,当用户点击倒带按钮时,它应该停止以前正在进行的更新viewcontrollers播放按钮的处理

-(void)rewind:(id)sender{

audioPlayer.currentTime = 0;

[audioPlayer play];

MainViewController *viewController = [[MainViewController alloc] init];

viewController.view.frame = CGRectMake(0, 0, 320, 480);

[self.view addSubview:viewController.view]; 

[self.view addSubview:toolbar];

[viewController release];

self.timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:@selector(displayviewsAction:) userInfo:nil repeats:NO];

}

-(void)playpauseAction:(id)sender 
{

  if  

  ([audioPlayer isPlaying]){

 [sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateSelected];

      [audioPlayer pause];

  } else {

 [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];

      [audioPlayer play];


      self.timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:@selector(displayviewsAction:) userInfo:nil repeats:NO];
  }  

}

- (void)displayviewsAction:(id)sender
{   
FirstViewController *viewController = [[FirstViewController alloc] init];

viewController.view.frame = CGRectMake(0, 0, 320, 480);

[self.view addSubview:viewController.view];

[self.view addSubview:toolbar];

[viewController release];      

  self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(secondViewController) userInfo:nil repeats:NO];     

}   

1 个答案:

答案 0 :(得分:0)

我使用

修复了它
[timer invalidate];

在倒带语句的开头,现在它正常工作。

所以我的问题已解决。