Reputation: 1388
i am facing an issue. I created an UICollectionView
and if i scroll that much, that i cannot see the first row anymore, then the App crashes. I really do not know how to solve this. This is the part of my App where i create the CollectionView
. The content of the Cells are images, which are holding a thumbnail of all videos of my movies synchronized with iTunes. Everything is working, but not the scrolling over more then 1 row.
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
return itemList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
// we're going to use a custom UICollectionViewCell, which will hold an image and its label
//NSLog(@"%@",indexPath);
VPCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
// make the cell's title from title of current MPMediaItem
MPMediaItem *item = [itemList objectAtIndex:cellMediaItemCounter];
NSString* title = [item valueForProperty:MPMediaItemPropertyTitle];
cell.label.text = [NSString stringWithFormat:@"%@", title];
NSNumber *duration=[item valueForProperty:MPMediaItemPropertyPlaybackDuration];
double seconds = duration.doubleValue;
int secondsInt = round(seconds);
int minutes = secondsInt/60;
secondsInt -= minutes*60;
cell.durationLabel.text = [NSString stringWithFormat:@"%.2i:%.2i", minutes, secondsInt];
// load the thumbnail for this cell
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIImage *thumbnail = [player thumbnailImageAtTime:13.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//set thumbnail to cell image
cell.image.image = thumbnail;
cellMediaItemCounter++;
//pause initiated player (to get thumbnail), if not it's playing in background
player=nil;
return cell;
}
Thank you very much.
Upvotes: 0
Views: 1819
Reputation: 2053
Seems like an index out of range exception. Put this:
MPMediaItem *item = [itemList objectAtIndex:indexPath.row];
instead of
MPMediaItem *item = [itemList objectAtIndex:cellMediaItemCounter];
Upvotes: 3