我面临一个问题。我创建了一个UICollectionView
,如果我滚动那么多,我再也看不到第一行,那么应用程序就会崩溃。我真的不知道如何解决这个问题。这是我的应用程序的一部分,我在其中创建CollectionView
. 单元格的内容是图像,其中包含与 iTunes 同步的我的电影的所有视频的缩略图。一切正常,但不是滚动超过 1 行。
- (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;
}
非常感谢。