我是 Objective-C 的新手。我的问题是我有一个主细节设计的应用程序,它有一个表格列出英语单词及其威尔士语翻译。这很好用,但我也想通过 UIButton 为发音添加声音。我知道如何播放一种声音,但是当我按下按钮时,如何为正确的文字播放发出相应的声音?
我的表如下:
-(void)createWordData {
NSMutableArray *nounWords;
NSMutableArray *verbWords;
_wordSections=@[@"Nouns", @"Verbs"];
nounWords=[[NSMutableArray alloc] init];
verbWords=[[NSMutableArray alloc] init];
[nounWords addObject:@{@"English":@"girl",@"Cymraeg":@"y ferch (f.)",@"Sound":@"Merch"}];
[nounWords addObject:@{@"English":@"boy",@"Cymraeg":@"y bachgen (m.)",@"Sound":@"Bachgen"}];
[nounWords addObject:@{@"English":@"cat",@"Cymraeg":@"y gath (f.)",@"Sound":@"Cath"}];
[nounWords addObject:@{@"English":@"dog",@"Cymraeg":@"y ci (m.)",@"Sound":@"Ci"}];
[verbWords addObject:@{@"English":@"walk",@"Cymraeg":@"cerdded",@"Sound":@"Cerdded"}];
[verbWords addObject:@{@"English":@"run",@"Cymraeg":@"rhedeg",@"Sound":@"Rhedeg"}];
[verbWords addObject:@{@"English":@"play",@"Cymraeg":@"chwarae",@"Sound":@"Chwarae"}];
[verbWords addObject:@{@"English":@"sleep",@"Cymraeg":@"cysgu",@"Sound":@"Cysgu"}];
_wordData=@[nounWords,verbWords];
}
播放动作如下:
- (IBAction)pronunciation:(id)sender {
SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle]
pathForResource:@"Cath" ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)
[NSURL fileURLWithPath:soundFile]
, &soundID);
AudioServicesPlayAlertSound(soundID);
}