次の実装では、何を試しても、カルーセルに画像が表示されることはありません。代理人とデータソースを設定しました。画像をダウンロードしながら、あなたはカルーセルをリロードする必要がカルーセルが動作しない
ヘッダー
#import "UIImageView+AFNetworking.h"
#import <AFNetworking/AFNetworking.h>
#import "iCarousel.h"
@interface GalleryViewController : UIViewController<iCarouselDataSource, iCarouselDelegate>
@property (strong, nonatomic) UIImageView *galleryImageView;
@property (nonatomic, strong) NSMutableArray *gElements;
@property (nonatomic, strong) iCarousel *carousel;
@end
実装
- (void)viewDidLoad {
[super viewDidLoad];
self.gElements = [[NSMutableArray alloc] init];
self.carousel = [[iCarousel alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeCylinder;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
[self loadGalleryImages];
dispatch_async(dispatch_get_main_queue(), ^{
[self.carousel reloadData];
});
});
}
- (NSInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [gElements count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)carouselView
{
self.galleryImageView = nil;
//create new view if no view is available for recycling
if (carouselView == nil)
{
carouselView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
self.galleryImageView = [[UIImageView alloc]initWithFrame:carouselView.frame];
self.galleryImageView.tag = 0;
[carouselView addSubview:self.galleryImageView];
}
else
{
self.galleryImageView = (UIImageView*)[carouselView viewWithTag:0];
}
if([gElements count] >0)
{
// gElement has 10 NSURL objects
NSURLRequest *request = [NSURLRequest requestWithURL:[gElements objectAtIndex:index]];
NSLog(@ "index %ld", (long)index);
__weak typeof(self) weakSelf = self;
[galleryImageView setImageWithURLRequest:request
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakSelf.galleryImageView.image = image;
}
failure:nil];
}
return carouselView;
}
動作しません。 – hotspring
私は私のプロジェクトで働いているブロック全体を投稿します。 – KKRocks
ハードコードされた単一のイメージでテストしましたが、まだ表示されません。 – hotspring