0

当我对 NSMutableArray 的内容执行 NSLog 时,它返回:

(
    hat,
    hat
)

那么为什么当我像这样执行 NSLog 时NSLog(@"%@", [pro.matches objectAtIndex:0]);它会因错误而崩溃:*** 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]);
    }];
4

2 回答 2

1

当您第一次记录由于完成块的工作方式而没有任何内容的内容时,请尝试以下操作:

[pro refreshMatchesWithCallback:^ 
{
    //[self.tableView reloadData];
    if(pro.matches.count > 0) {
       NSLog(@"the count of a lifetime is %@", [pro.matches objectAtIndex:0]);
    }
}];

希望这可以帮助!

山姆

于 2012-05-02T14:52:22.737 回答
0
always prefer to use this approach

for(Object* obj in arra)
{
...

}

如果计数器大于 0,这将进入循环。不需要检查

欢呼:P

于 2012-05-02T14:56:44.137 回答