Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you never download imageData. you assign it the request object . thats why you get the warning too. a NSURLConnection object is not a NSData object: <code>NSData *imgData = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self]; //"Incompatible pointer types initializing ..." warning here</code></p> <p>I would today rewrite it using the startAsyncConnection method. sec</p> <p>-- there you go, untested and written in text edit but it should get you started (I reused most of your code but cut it down a lot too)</p> <pre><code>#import "RootViewController.h" @interface RootViewController () @property(assign) IBOutlet UIScrollView *mainScroll; @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [self getJSONAndImageData]; } - (void)getJSONAndImageData { NSURL *url = [NSURL URLWithString:@"http://My server goes here/json.php"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse*r, NSData*d, NSError*e) { [self parseJSONAndGetImages:d]; }]; } - (void)parseJSONAndGetImages:(NSData*)data { NSMutableArray *urlArray = [[NSMutableArray alloc] init]; //This is where all the JSON Parsing is being done. //Turn off the data indicator, because the download is complete. [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; NSArray *jsonArray = (NSArray*)[NSJSONSerialization JSONObjectWithData:data options:nil error:nil]; //"Incompatible pointer types initializing ..." warning here =&gt; likely not an array then assert([jsonArray isKindOfClass:[NSArray class]]); //could be made in one liner with KVC //get the URL strings out of the jsonArray for (int x = 0; x &lt; jsonArray.count; x++) { NSString *urlString = [[jsonArray objectAtIndex:x] objectForKey:@"image_URL"]; NSLog(@"String is %@ ", urlString); [urlArray addObject:urlString]; } [self loadImageArray:urlArray handler:^(NSArray* imageArray) { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; for (int x = 0; x &lt; imageArray.count; x++) { CGRect frame; frame.origin.x = self.mainScroll.frame.size.width * x; frame.origin.y = 0; frame.size = self.mainScroll.frame.size; UIImageView *nextIV = [[UIImageView alloc] initWithFrame:frame]; [nextIV setImage:imageArray[x]]; [self.mainScroll addSubview:nextIV]; //NSLog(@"Pass %d", x); } self.mainScroll.contentSize = CGSizeMake(self.mainScroll.frame.size.width * imageArray.count,1.0); }]; } //for SIMPLICITY I do synchronous networking here! - (void)loadImageArray:(NSArray *)urlArray handler:(void(^)())handler { dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSMutableArray *imageArray = [NSMutableArray array]; for (int y = 0; y &lt; urlArray.count; y++) { NSString *urlString = [urlArray objectAtIndex:y]; NSLog(@"Array String is: %@ ", urlString); NSURL *arrayURL = [NSURL URLWithString:urlString]; NSURLRequest *imageRequest = [NSURLRequest requestWithURL:arrayURL]; NSData *imgData = [NSURLConnection sendSynchronousRequest:imageRequest returningResponse:nil error:nil]; UIImage *image = [UIImage imageWithData:imgData]; [imageArray addObject:image]; } dispatch_async(dispatch_get_main_queue(),^ { handler(imageArray); }); }); } @end </code></pre>
 

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