Question

Suppose I generated the 100 image views. First of all I wish to generate all 100 image views and add them in my scroll view.

So image view are clearly display it’s in position using background color

Then after I want to set images into the image view. I have to types of Dictionary (Which comes from the another class). One Dictionary into set Already Downloaded images and another one into only generate object (Remaining download images). I am downloading this image Asynchronously.

Then how can I set images into the image view?

    -(void)GenerateImageView{  

       for (int ivalue = 0; ivalue < 100; ivalue++) {

         imageView = [[UIImageView alloc] init];

        //Give tag to the image view
          imageView.tag = ivalue;
          [imageView setBackgroundColor:[UIColor whiteColor]];

          CGFloat xOrigin =ivalue *ascrollView.frame.size.width+50;

          imageView.frame=CGRectMake(xOrigin40,imgYpos,ascrollView.frame.size.width-20, scrollViewHight); 

        //set imageview into the scroll view
         [ascrollView addSubview:imageView];

           }

    }
Was it helpful?

Solution 2

u can not access the directly image view.And also make sure ur tag not start with 0.bcs 0 is a by default main view tag

imageView = (UIImageView *)[ascrollView viewWithTag:some_tag];

imageView.image = your_UIImage_object;

OTHER TIPS

Then how can I set images into the imageview?

    UIImageView *imageView = [ascrollView viewWithTag:some_tag];
    if ([imageView isKindOfClass:[UIImageView Class]])
        imageView.image = your_UIImage_object;

You could use the code Avt suggested, but instead of reinventing the wheel, I would suggest to look into

AFNetworking

an open-source networking lib. It comes with an extension to the UIImageView which allows you to load the images asynchronously out-of-the-box. There are many other useful features too.

After importing the extension you could then use:

[imageView setImageWithURL:[NSURL URLWithString:@"yourImageURL"]];

the image gets loaded asynchronously and automaticly set when it's done loading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top