我想用數據填充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