views:

72

answers:

1

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?

+2  A: 

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....

Johan Kool
Its working but semiperfectly. Problem is that even though the images are being loaded, if i am doing any current action on the scrollview then only it works as i want, ie, replacing the current images with the new ones, otherwise it will come as in the earlier case. But if i am just playing with it, i am able to see each of them loading and replacing the previos ones. How to make it visible when i am not even doing anything?
wolverine
Not easy to say without seeing the code. You may have to let the runloop know that your view needs to update it's drawing with the setNeedsDisplayInRect: method.
Johan Kool