我正在创建一个ios应用程序,我在运行时使用AFNetworking在我的轮播中传递五个图像。问题是,我第一次从服务器下载图像,所以我不能一次下载所有图像作为响应有时我得到3或4,如果需要从服务器下载五个图像。每个图像大小约为100 KB。
这是我的代码:
for (int i=0; i<[slideShowArray count]; i++) {
SlideShow *pro = [[SlideShow alloc] init];
pro = [slideShowArray objectAtIndex:i];// slideShowArray is an array of image urls
NSURL *url = [NSURL URLWithString:pro.imageUrl];
UIImageView *imageview=[[UIImageView alloc]init];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
imageview.image = responseObject;
[slideshow addImage:imageview.image]; // here i am adding multiple image on my carousel
if (!isLoadSlideshow) {
isLoadSlideshow = TRUE;
[slideshow start]; // this is to start my carousel to slide images after some delay
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Image error: %@", error);
}];
[requestOperation start];
}
由于我已经添加了页面控制以及移动图像,因此我从服务器获取了五张图像。作为输出,它在页面控制中显示5个点,但图像滑块未到达最后一个。我该如何解决这个问题?
谢谢。