Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c plist读取失败_Objective C_Plist_Nsdictionary - Fatal编程技术网

Objective c plist读取失败

Objective c plist读取失败,objective-c,plist,nsdictionary,Objective C,Plist,Nsdictionary,我在将数据从plist转换为对象时遇到一些问题 plist具有以下结构 我用以下代码读取该文件 -(void)readAnimationsFromPlist { NSDictionary *dict; NSString *path = [[NSBundle mainBundle] pathForResource:@"Animationen" ofType:@"plist"]; dict = [[NSDictionary alloc] initWithContentsOf

我在将数据从plist转换为对象时遇到一些问题

plist具有以下结构

我用以下代码读取该文件

-(void)readAnimationsFromPlist
{
    NSDictionary *dict;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Animationen" ofType:@"plist"];
    dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    CCLOG(@"%@", [dict description]);
    for (NSDictionary *items in dict)
    {
        Animation *animation = [[Animation alloc] init];
        animation.name = items.description;
        CCLOG(@"%@", items);
        animation.delay = [items valueForKey:@"delay"]; //(1)
        animation.phases = [items valueForKey:@"phases"];
        CCLOG(@"Animation %@ mit %i frames eingelesen", items.description, animation.phases.count);
        [animationen setObject:animation forKey:animation.name];
        [animation release]; //(2)
    }
    [dict release];
    CCLOG(@"%i animationen eingelesen", [animationen count]);
 }
我现在的问题是,在标有(1)的行中没有读取数据,总是抛出以下异常

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCFString 0x55d3ba0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key delay.'
由于未捕获异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:此类不符合密钥延迟的键值编码。”
我找到了一些关于此消息的信息,但没有任何帮助

  • 没有绑定问题(使用中没有IB)
  • 当我使用objectForKey时,还有一个错误
调试时,当我查看inspector窗口时,它会显示项的类型为NSCFString,值为'hauptgewin',但它应该是一个字典。我试图把它显式地放到一本词典中,但没有任何改变

我能做些什么来解决这个问题

在位置(2)上,我必须释放该位置,否则我可以删除此行吗?

/2是正确的

-(void)readAnimationsFromPlist
{
    NSDictionary *dict;
    NSString *path = [[NSBundle mainBundle] pathForResource:@"untitled" ofType:@"plist"];
    dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    NSLog(@"Dictionary is: %@", dict);
    for(id key in dict)
    {
        Animation *animation = [[Animation alloc] init];
        animation.name = key;
        CCLOG(@"%@", key);
        animation.delay = [[dict valueForKey:key] valueForKey:@"delay"]; //(1)
        animation.phases = [[dict valueForKey:key] valueForKey:@"phases"];
        CCLOG(@"Animation %@ mit %i frames eingelesen", items.description, animation.phases.count);
        [animationen setObject:animation forKey:animation.name];
        [animation release]; //(2)

    }
    [dict release];
}

但这只适用于单个动画。在我的plist中应该有更多的动画(如类名所示:)。我创建了一些与第一个条目平行的动画。我应该在上面再加一本字典来阅读吗?谢谢,现在可以了。没见过,还有另一本字典要查。调试时看不到对象中有什么数据,这让我很恼火。我只看到那些该死的指针,没有数据。