Objective c plist读取失败
我在将数据从plist转换为对象时遇到一些问题 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
-(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时,还有一个错误
-(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中应该有更多的动画(如类名所示:)。我创建了一些与第一个条目平行的动画。我应该在上面再加一本字典来阅读吗?谢谢,现在可以了。没见过,还有另一本字典要查。调试时看不到对象中有什么数据,这让我很恼火。我只看到那些该死的指针,没有数据。