objective c - How to add UIImage object into NSMutableArray in iOS -


i'm trying add uiimage objects array not being added. please help

my code:

imagearray = [[nsmutablearray alloc] init]; arry = [[nsmutablearray alloc] init];  [arry addobject:@"http://adjingo.2cimple.com/content/151/image/6291.jpg"]; [arry addobject:@"http://adjingo.2cimple.com/content/151/image/6290.jpg"];  //fetch images web , store in array (int i=0; i<[arry count]; i++) {     nsstring *string=[arry objectatindex:i];     nsurl *url=[nsurl urlwithstring:string];     nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url];     [nsurlconnection sendasynchronousrequest:request                                    queue:[nsoperationqueue mainqueue]                        completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {                            if ( !error )                            {                                uiimage *image = [[uiimage alloc] initwithdata:data];                                 //store image in imagearray                                [imagearray insertobject:image atindex:i];                             } else{                             }                        }]; }  nslog(@"%lu",(unsigned long)[imagearray count]); //this line showing 0 count 

when i'm printing count of array containing uiimage objects, showing 0.

(i want download images @ once in array, show un uiimageview slideshow).

please guide me. thank you!

there several problems.

  1. [[nsmutablearray alloc] init] not allocate memory , items can not added beyond current size. [nsmutablearray arraywithcapacity:size] allocate memory , objects can inserted @ index , including current size. see nsmutablearray documentation.

  2. immediately after sendasynchronousrequest block no images have ben downloaded, happen downloads complete.

  3. starting large number of downloads @ once can present performance problem.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -