Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone - performSelectorInBackground image loading
    primarykey
    data
    text
    <p>i'm loading images into a UIView inside a UIscrollview using performSelectorInBackground to fetch the images from the URL. Images are getting downloaded correctly into an array but when I assign to the UIImageView these images all the images are assigned to the last page of Scroll view.</p> <pre><code>@implementation DetailViewController - (id)initWithDataSource:(id&lt;TabBarElementProtocol,UITableViewDataSource&gt;)theDataSource { if ([self init]) { // Scroll View scrollView = [[UIScrollView alloc]init]; //a page is the width of the scroll view scrollView.delegate = self; scrollView.pagingEnabled = YES; scrollView.frame = CGRectMake(0, 0, 320, 300); scrollView.contentSize = CGSizeMake(320*10, 300); scrollView.backgroundColor = [UIColor clearColor]; scrollView.showsHorizontalScrollIndicator = NO; scrollView.showsVerticalScrollIndicator = NO; scrollView.scrollsToTop = NO; scrollView.bounces = NO; scrollView.showsHorizontalScrollIndicator = NO; scrollView.pagingEnabled = YES; [self.view addSubview:scrollView]; scrollView.contentOffset = CGPointMake(10*320, 0); [self displayView]; } return self; } -(void) displayView{ DouglasAppDelegate *delegate = (DouglasAppDelegate *)[[UIApplication sharedApplication] delegate]; for (int i=0; i &lt; 10; i++) { myview = [[UIView alloc] init]; myview.frame = CGRectMake(320*i , 0, 320, 300); [myview setBackgroundColor: [UIColor whiteColor]]; pictureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(179, 11, 100, 100)]; pictureImageView.tag = i; [myview addSubview: pictureImageView]; [pictureImageView release]; // Picture URL is accessed dynamically and loading correctly. [dataArray insertObject:[NSMutableArray arrayWithObjects:picUrl,[NSString stringWithFormat:@"%d", i],nil] atIndex:i]; [scrollView addSubview:myview]; } [self performSelectorInBackground:@selector(loadImageInBackground:) withObject:dataArray]; //Pager control tpageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 300 , 320, 17)]; tpageControl.backgroundColor = [UIColor clearColor]; tpageControl.numberOfPages = [delegate.NeuEntries count]; tpageControl.currentPage = delegate.neuDetailIndex; zumPage = delegate.neuDetailIndex ; [tpageControl addTarget:self action:@selector(pageTurn:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview: tpageControl]; } - (void) loadImageInBackground:(NSMutableArray *)urlAndTagReference { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSData *imgData; UIImage *img; NSMutableArray *arr1 = [[NSMutableArray alloc] initWithCapacity: [urlAndTagReference count]]; for(int i=0; i&lt;[urlAndTagReference count] ;i++) { NSString *url = [[urlAndTagReference objectAtIndex:i] objectAtIndex:0]; NSURL *imgURL = [NSURL URLWithString:url]; imgData = [NSData dataWithContentsOfURL:imgURL]; img = [[UIImage alloc] initWithData:imgData]; [arr1 insertObject:[NSMutableArray arrayWithObjects:img,[[urlAndTagReference objectAtIndex:i]objectAtIndex:1],nil] atIndex:i]; } [self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr1 waitUntilDone:YES]; } - (void) assignImageToImageView:(NSArray *)imgAndTagReference { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for(int i=0; i&lt;[imgAndTagReference count] ;i++){ UIImage *img = [[UIImage alloc] init]; img = [[imgAndTagReference objectAtIndex:i] objectAtIndex:0]; NSLog(@"img %@",img); // SAME IMAGES OVERLAPPING ON LAST PAGE OF SCROLL VIEW???????????????? [pictureImageView setImage:img]; } } - (void) pageTurn:(UIPageControl*) aPageController{ int whichPage = aPageController.currentPage; scrollView.contentOffset = CGPointMake(320.0f * whichPage, 0.0f); } - (void)scrollViewDidScroll:(UIScrollView *)sender { CGPoint offset = sender.contentOffset; tpageControl.currentPage = offset.x / 320.0f; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload