收录日期:2021/01/26 16:58:49 时间:2010-03-31 04:30:18 标签:iphone,objective-c,cocoa-touch,xcode

in my code:

#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];

}

But it is showing a warning that Class MyViewController does not implement AVAudioplayerDelegate.

Anyone please help. I had included the AVFoundation.Framework.

That warning should not affect the actual function of the code.

If you want to suppress the warning, in the header of your view controller do this:

@interface MyViewController : UIViewController <AVAudioPlayerDelegate> {

This lets the compiler know that your class does respond to the AVAudioPlayerDelegate (even though all the methods in that protocol are optional). See here.