How to tell if blocks in loop all have completed executing?

前端 未结 4 1940
一个人的身影
一个人的身影 2020-12-02 19:10

I have a loop set up that downloads a series a images which I will later use for to animate using the animationImages property of UIImageView. I wo

4条回答
  •  星月不相逢
    2020-12-02 19:58

    for (PFObject *pictureObject in objects){
    
        PFFile *imageFile = [pictureObject objectForKey:@"image"];
        NSURL *imageFileURL = [[NSURL alloc] initWithString:imageFile.url];
        NSURLRequest *imageRequest = [NSURLRequest requestWithURL:imageFileURL];
    
        [tokenImageView setImageWithURLRequest:imageRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
           [self.downloadedUIImages addObject:image]; //This is a mutableArray that will later be set to an UIImageView's animnationImages
           if([[objects lastObject] isEqual:pictureObject]) {
               [self animateImages];
           }
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
            NSLog(@"Error %@", error);
            if([[objects lastObject] isEqual:pictureObject]) {
               [self animateImages];
           }
        }];
    
    }
    
    - (void)animateImages {
        //do animation here.
    }
    

提交回复
热议问题