Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios : How to load images from URL to page control using scroll view

I'm new in iOS. Now I want to load view images from URL to page control using scroll view. When I run the program the first image is shown but when I try to slide to next image or I move to another page program is not responding. My guess is probably related to the size of image.

The following is my code to load the image. I put this code in -(void) viewDidLOad...

CGRect screenShot = screenView.frame;
screenShot.origin.y = description.frame.origin.y + description.frame.size.height + 30;
screenView.frame = screenShot;

pageControlBeingUsed = NO;

for (int i = 0; i < [myArrayImagesURL count]; i++) {
    CGRect frame;
    frame.origin.x = self.scrollView.frame.size.width * i;
    frame.origin.y = 0;
    frame.size = self.scrollView.frame.size;
      UIImageView *iv = [[[UIImageView alloc] initWithFrame:CGRectMake(scrollView.bounds.size.width * i, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)] autorelease];
    iv.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                                       [NSURL URLWithString:[myArrayImagesURL objectAtIndex:i]]]];

    [self.scrollView addSubview:iv];
    [iv release];
}

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [myArrayImagesURL count], self.scrollView.frame.size.height);

self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = [myArrayImagesURL count];
like image 393
dagger24 Avatar asked Nov 04 '22 14:11

dagger24


1 Answers

It looks like you have set the imageView to autorelease and the released it. This should be wrong. Try removing the autorelease tag when you create the imageView. It should be properly retained now.

UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(scrollView.bounds.size.width * i, 0, scrollView.bounds.size.width, scrollView.bounds.size.height)];
like image 138
Madhu Avatar answered Nov 15 '22 00:11

Madhu