当我对NSMutableArray的内容执行NSLog时,它返回:
(
hat,
hat
)
那么为什么当我像这样NSLog(@"%@", [pro.matches objectAtIndex:0]);
执行NSLog时,它会因错误而崩溃:*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
太奇怪了
这是我填写的地方:
[self.matches removeAllObjects];
NSArray *JSONarray = [[NSArray alloc] initWithArray:[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]];
int i;
for (i=0; i<[JSONarray count]; i++) {
//[self.matches addObject:[JSONarray objectAtIndex:i]];
[self.matches addObject:@"hat"];
}
//NSLog(@"boys with bo%@", [[matches objectAtIndex:1] objectForKey:@"host"]);
block();
//JSON and add to matches.
}
}];
block();
这就是我所说的:
[pro refreshMatchesWithCallback:^
{
//[self.tableView reloadData];
NSLog(@"the count of a lifetime is %@", [pro.matches objectAtIndex:0]);
}];
答案 0 :(得分:1)
当您第一次记录内容时,由于完成块的工作方式,它没有任何内容,请尝试:
[pro refreshMatchesWithCallback:^
{
//[self.tableView reloadData];
if(pro.matches.count > 0) {
NSLog(@"the count of a lifetime is %@", [pro.matches objectAtIndex:0]);
}
}];
希望这有帮助!
萨姆
答案 1 :(得分:0)
always prefer to use this approach
for(Object* obj in arra)
{
...
}
如果计数器大于0,这将进入循环。不需要检查
Cheerz:P