我有一部分代码返回 numberOfRowsInSection。
代码
for (NSDictionary *consoleDictionary in [self arrayFromJSON]) {
if ([[consoleDictionary objectForKey:@"model"] isEqualToString:@"PlayStation 3"]) {
NSLog(@"%@", consoleDictionary);
}
}
输出
2013-02-03 22:37:08.468 PageControl01[5782:c07] {
console = PlayStation;
game = "007 Legends";
id = 1;
model = "PlayStation 3";
publisher = "Electronic Arts";
}
2013-02-03 22:37:08.478 PageControl01[5782:c07] {
console = PlayStation;
game = "Ace Combat: Assault Horizon";
id = 2;
model = "PlayStation 3";
publisher = Namco;
}
这显然是正确的,因为它记录了所有"PlayStation 3"
模型。然而,这不是我需要的。我想记录"PlayStation 3"
's 的数量。所以我稍微调整一下代码,然后:
for (NSDictionary *consoleDictionary in [self arrayFromJSON]) {
if ([[consoleDictionary objectForKey:@"model"] isEqualToString:@"PlayStation 3"]) {
NSLog(@"%d", [consoleDictionary count]);
}
}
输出
2013-02-03 22:39:43.605 PageControl01[5816:c07] 5
2013-02-03 22:39:43.605 PageControl01[5816:c07] 5
这一个非常接近但又如此接近。而不是记录数字5
,它应该记录数字,2
因为只有2
"PlayStation 3"
.
请帮忙。