0

应用程序崩溃和消息是程序接收到的信号“EXC_BAD_ACCESS”,当故意多次按下倒带按钮以测试 iPhone 设备上的应用程序时。

-(void)rewind:(id)sender{
[timer invalidate];
audioPlayer.currentTime = 0;
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 playpauseAction:_playButton];
}

-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
    [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
    [audioPlayer pause];
    [self pauseTimer];
    [self pauseLayer:self.view.layer];

}else{
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
    [self resumeLayer:self.view.layer];

    if(isFirstTime == YES)
    {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                      target:self
                                                    selector:@selector(displayviewsAction:)
                                                    userInfo:nil
                                                     repeats:NO];
        isFirstTime  = NO;
    }
    } 
    }

 -(void)pauseTimer{
pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];

previousFireDate = [[timer fireDate] retain];

[timer setFireDate:[NSDate distantFuture]];
  }

-(void)resumeTimer{
float pauseTime = -1*[pauseStart timeIntervalSinceNow];

[timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];
}


 -(void)resumeLayer:(CALayer*)layer
 {
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
 }

 -(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
 }

我不知道为什么它崩溃可能是因为恢复计时器或者可能是因为我释放的视图控制器。

4

1 回答 1

1

Why do you alloc and init your MainViewController inside of your rewind function? that seems odd to me, normally you only need to initialize your viewcontroller once, not every time a method is called. And similarly, you release it at the end of the method, which is also strange. Generally errors that take multiple clicks to be caused are caused by memory management problems. I'm guessing that something is being removed from memory (possibly your view controller) and then you are trying to access it, giving you a bad access error.

To debug this, use NSZombies, which allows you to see what was removed from memory. A tutorial of how to use it can be found here

于 2012-06-26T15:46:40.950 回答