2010-03-31 68 views
0

在我的代码的时候:问题与播放声音的按钮被点击

#import "MyViewController.h" 
#import "AVFoundation/AVAudioPlayer.h" 


- (IBAction)playSound{ 
    AVAudioPlayer *myExampleSound; 

    NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"myaudiofile" ofType:@"caf"]; 

    myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL]; 

    myExampleSound.delegate = self; 

    [myExampleSound play]; 

} 

但它显示出类MyViewController没有实现AVAudioplayerDelegate警告。

请人帮忙。我已经包括AVFoundation.Framework。

回答

2

该警告不应该影响代码的实际功能。

如果你想取消此警告,在您的视图控制器的标题做到这一点:

@interface MyViewController : UIViewController <AVAudioPlayerDelegate> { 

这让编译器知道你的类确实给AVAudioPlayerDelegate(回应,即使在所有的方法协议是可选的)。见here

+0

它的工作!非常感谢你!! – isarathg 2010-03-31 04:06:50

相关问题