0

在 Xcode 的 Storyboard 模式下。当您使用导航控制器时,后退按钮会自动出现。

通常要播放我的声音,我会从选择器或操作中调用我的任务。

如何使用后退按钮播放此声音?我该如何编码,因为后退按钮会自动出现在我的视图中?

- (void)myTask {
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/pop.wav"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;

//Initialize our player pointing to the path to our resource
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
          [NSURL fileURLWithPath:resourcePath] error:&err];

if( err ){
    //bail!
    NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
    //set our delegate and begin playback
    player.delegate = self;
    [player play];
}
}

问候

布莱克

4

1 回答 1

1

你可以玩- (void)viewWillDisappear:(BOOL)animated { // in here }

于 2013-05-22T08:17:43.730 回答