我试图用按钮发出声音。由于缺乏了解,我已经达到了停止点。我尝试了大约4个小时试图解决这个问题,但无济于事。有人能帮我吗?我收到错误,“使用未声明的标识符'soundFile '”这里是我的.m文件..
//
// FirstViewController.m
// simpleApp
//
// Created by Abby Russell on 11/29/13.
// Copyright (c) 2013 Abby Russell. All rights reserved.
//
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playsound:(id)sender {
SystemSoundID soundID;
NSString *buttonName=[sender currentTitle];
NSString *path = [[NSBundle mainBundle] pathForResource:buttonName ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)
[NSURL fileURLWithPath: soundFile], &
soundID;
AudioServicesPlaySystemSound(soundID);
}
@end
非常感谢聪明的人!
答案 0 :(得分:2)
soundFile需要是声音文件的NSString路径。看起来你刚刚输入了文本“soundFile”而没有任何名为soundFile的NSString。尝试用“path”替换soundFile。