在我的Controller.h文件中...我列出了我正在使用的NSDictionary以及要拉的项目。但是我在识别录音变量时遇到了问题...
@property (nonatomic, retain) NSDictionary *dataForCurrentLevel;
@property (nonatomic, retain) IBOutlet UILabel *Name;
@property (nonatomic, retain) IBOutlet UILabel *Author;
@property (nonatomic, retain) IBOutlet UILabel *Time;
@property (nonatomic, retain) NSString *Recording;
在我的Controller.m文件中....
- (void)viewDidLoad
{
// Configure the user interface by extracting the data from the dictionary
Name.text = [dataForCurrentLevel valueForKey:@"Name"];
Author.text = [dataForCurrentLevel valueForKey:@"Author"];
Time.text = [dataForCurrentLevel valueForKey:@"Time"];
//以上几行是AOK。构建拉入并在我的新视图控制器中显示数据没有问题。但是,我无法提取与字典项一起使用的音频m4a文件。使用下面的代码,我可以播放一个特定的音频文件...但是如何更改下面的代码以拉入当前表级别的plist字典中列出的音频文件?仅供参考,音频文件与对象键一起列出:"录制"键入:" String"和变量值如:" buzz.4ma"
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"buzz" ofType:@"m4a"]];
self.myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error:nil];
//如何让pathForResource在plist字典中选择变量音频文件?
答案 0 :(得分:1)
我改变了我的plist字典并找到了解决方案: NSDictionary * dict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; dict = [dict objectForKey:@“Root”];
for (int i = 0; i < numberOfSongs; i++){
NSDictionary *songInfo = [dict objectForKey:[NSString stringWithFormat:@"Item%d",i]];