2010-03-31 89 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