我想用数据填充gridView。我正在使用从Web服务返回的数据执行此操作。为了填补我有一个属性loopIndex计数阵列的哪个对象应该是下一个单元格。你可以在这里看到CellForRowAtIndexPath的方法。GridView总是在向下滚动时向下滚动
- (NRGridViewCell*)gridView:(NRGridView *)gridView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyCellIdentifier = @"MyCellIdentifier";
NRGridViewCell* cell = [gridView dequeueReusableCellWithIdentifier:MyCellIdentifier];
if(cell == nil){
cell = [[NRGridViewCell alloc] initWithReuseIdentifier:MyCellIdentifier];
[[cell textLabel] setFont:[UIFont boldSystemFontOfSize:11.]];
[[cell detailedTextLabel] setFont:[UIFont systemFontOfSize:11.]];
}
NSLog(@"loopIndex: %d",_loopIndex);
_players = [self getTeam];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[[_players objectAtIndex:_loopIndex]valueForKey:@"image"]]];
UIImage *image = [[UIImage alloc]initWithData:imgData];
cell.imageView.image = image;
cell.textLabel.text = [[_players objectAtIndex:_loopIndex]valueForKey:@"name"];
cell.detailedTextLabel.text = [[_players objectAtIndex:_loopIndex]valueForKey:@"position"];
if(_loopIndex < [[self getTeam]count]){
_loopIndex++;
}else {
_loopIndex = _loopIndex;
}
return cell;
}
这里您会看到该错误。它总是在NSData线上崩溃。
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFArray objectAtIndex:]: index (30) beyond bounds (30)'
我认为我的循环索引有问题。因为当我只使用一个静态值。假设说1O像这样
cell.textLabel.text = [[_players objectAtIndex:_loopIndex]valueForKey:@"name"];
它不会崩溃。有谁知道我可以如何解决它?
亲切的问候
您是否尝试在其上放置一个中断点并逐句通过代码以查看错误的位置? – Dcritelli