I want to get many images from diffrent url and set it like image's buttons . I was trying to do this like it's showing above but nothing is happen . When i access this view controller it doesn't have any image for buttons and also neither the banner view is not showed... .
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
NSURL *url = [NSURL URLWithString: [pictureUrl objectAtIndex:i]];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
dispatch_async(dispatch_get_main_queue(), ^(void){
UIImage *img1 = [[UIImage alloc]initWithData:data];
img2.image = img1;
[bt setBackgroundImage:img2.image forState:UIControlStateNormal];
});
});
I recommend you to use a library that supports cache for images. For instance, I used AFNetworking for one of my projects and it is awesome. And it automatically handles in background for you. In my case I needed a library that automatically cancels a request when I start new one and it worked for me. You can see the code here. And you can see similiar solution from another thread as follows:
Hope it helps you.