我有一个自定义 plist:
<key>Ford</key>
<dict>
<key>name</key>
<string>Ford</string>
<key>color</key>
<string>green</string>
<key>price</key>
<integer>45000</integer>
</dict
<key>Toyota</key>
<dict>
<key>name</key>
<string>Toyota</string>
<key>color</key>
<string>blue</string>
<key>price</key>
<integer>40000</integer>
</dict
<key>BMW</key>
<dict>
<key>name</key>
<string>BMW</string>
<key>color</key>
<string>blue</string>
<key>price</key>
<integer>40000</integer>
</dict>
我也有一个UITableView
,我用这个 plist 中的一些汽车填充它。
NSEnumerator *enumerator = [dictionary objectEnumerator];
id returnValue;
while ((returnValue = [enumerator nextObject]))
{
if ([[returnValue valueForKey:@"color"]isEqualToString:@"blue")
{
[array addObject:[returnValue valueForKey:@"name"]];
}
现在,当我UITableView
的车满了,我想按价格对汽车进行分类NSSortDescriptor:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"price" ascending:YES];
[array sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
但是使用此代码,我的应用程序崩溃了:reason: '[<__NSCFString 0x89a1710> valueForUndefinedKey:]: this class is not key value coding-compliant for the key price.'
为什么会这样?