I have a UIScrollView and I add 9 imageview to it using the following code.
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"some url"]];
frame = [imageView frame];
frame.origin.x = x;
frame.origin.y = y;
[imageView setFrame:frame];
imageView.userInteractionEnabled = YES;
imageView.multipleTouchEnabled = YES;
[myScrollView addSubview:imageView];
}
}
I thought the UIScrollView will be shown and then we will see each image being loaded in tiles. But what happens is only after loading all the images only the UIScrollView comes into appearance with all the images.
How can i make UIScrollView come first, then show each of the images being loaded?
You are blocking the runloop until this whole block of code is executed. Therefore your app doesn’t get a chance to update its drawing. You need to do the drawing (more specifically, the downloading of your images) asynchronously. Once an image is downloaded, you can then add it to your UIScrollView. Note that you want to do this drawing on the main thread using a method like
performSelectorOnMainThread....