我正在實施iCarousel(使用coverflow類型)來顯示一些可在我的應用程序中使用的視頻的圖像。 (2 seperate carousels,同樣的問題)iOS - iCarousel僅使用可見視圖的索引
我使用numberOfItemsInCarousel(當前60)和viewForItemAtIndex的視頻數組來使用我的數組中的對象來構建視圖。
但是,只有5個視頻正在使用。所以有60件物品出現在旋轉木馬中,但它只是重複了5件物品。當我在'viewForItemAtIndex'中記錄索引時,它只被調用5次(0,1,... 5是日誌結果)。 經過一些測試後,似乎唯一被調用的索引默認情況下是輪播中可見的。
什麼給? *陣列已經過測試,以確保它們填充所有獨特的視頻。該數組很好,它與iCarousel方法有關。
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel{
if(carousel==freeCarousel){
NSLog(@"Free: %i",freeVideos.count);
return freeVideos.count;
}
if(carousel==feeCarousel){
NSLog(@"Fee: %i",feeVideos.count);
return feeVideos.count;
}
return 0;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view{
NSLog(@"TESTING");
if (view == nil){
//Copy array for easier use of global Video/File object
NSArray *copy = [[NSArray alloc] init];
if(carousel==freeCarousel){
copy = [NSArray arrayWithArray:freeVideos];
}
else if(carousel==feeCarousel){
copy = [NSArray arrayWithArray:feeVideos];
}
Videos *currentVideo = [copy objectAtIndex:index];
Files *file = [currentVideo valueForKey:@"files"];
NSLog(@"TITLE TEST: %@",currentVideo.title);
//Video Button
UIButton *buttonVideo = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 465, 310)];
[buttonVideo setTag:[currentVideo.videoID intValue]];
[buttonVideo addTarget:self action:@selector(showVideoDetails:) forControlEvents:UIControlEventTouchUpInside];
//Thumbnail
UIImageView *videoThumbnail = [[UIImageView alloc] initWithFrame:buttonVideo.bounds];
//Border
[videoThumbnail setBackgroundColor:[UIColor whiteColor]];
//Caption
UIImage *captionImage = [UIImage imageNamed:@"video-box-caption"];
UILabel *caption = [[UILabel alloc] initWithFrame:CGRectMake(0, videoThumbnail.frame.size.height-captionImage.size.height, videoThumbnail.frame.size.width, captionImage.size.height)];
[caption setBackgroundColor:[UIColor colorWithPatternImage:captionImage]];
[caption setTextAlignment:NSTextAlignmentCenter];
[caption setFont:[UIFont fontWithName:@"Open Sans Condensed" size:16]];
[caption setTextColor:[UIColor whiteColor]];
[caption setText:currentVideo.title];
[videoThumbnail addSubview:caption];
if(file.thumbnailPath!=(id)[NSNull null] || ![file.thumbnailPath isEqualToString:@"missing_image.png"]){
UIImage *thumbnailImage = [[DataManager sharedManager] generateThumbnailImage:currentVideo];
[videoThumbnail setImage:thumbnailImage];
[buttonVideo addSubview:videoThumbnail];
}else{
UIImage *thumbnailImage = [UIImage imageNamed:@"video-details-thumbnail"];
[videoThumbnail setImage:thumbnailImage];
[buttonVideo addSubview:videoThumbnail];
}
view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, buttonVideo.frame.size.width, buttonVideo.frame.size.height)];
[view addSubview:buttonVideo];
}
return view;
}
啊,好吧,這是我的想法實際上,只是還沒有測試過。看看並回復你。謝謝! – JimmyJammed
是的,它解決了它。謝謝! – JimmyJammed