Ios4 iphone sdk按钮声音

Ios4 iphone sdk按钮声音,ios4,Ios4,我想为按钮添加声音,请帮助我。您可以使用UIDevice类中的方法-(void)playInputClick。您可以使用静态方法+(UIDevice*)currentDevice访问此类的实例。使用此方法将默认输入声音附加到您自己的自定义UI。您不能仅复制和粘贴代码。必须使用堆栈溢出的格式选项。请更正。 - (IBAction)startPlayback:(UIButton *)sender {         NSString* resourcePath = [[NSBundle mai

我想为按钮添加声音,请帮助我。

您可以使用
UIDevice
类中的方法
-(void)playInputClick
。您可以使用静态方法
+(UIDevice*)currentDevice
访问此类的实例。使用此方法将默认输入声音附加到您自己的自定义UI。

您不能仅复制和粘贴代码。必须使用堆栈溢出的格式选项。请更正。
- (IBAction)startPlayback:(UIButton *)sender {
   
       NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
       resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
       NSLog(@"Path to play: %@", resourcePath);
       NSError* err;

     
       player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];

       if( err ){
           //bail!
           NSLog(@"Failed with reason: %@", [err localizedDescription]);
       }
       else{
           player.delegate = self;
           [player play];
       }
   
}
 - (IBAction)startPlayback:(UIButton *)sender {
       
           NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
           resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
           NSLog(@"Path to play: %@", resourcePath);
           NSError* err;

         
           player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];

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