0

I have the following problem:

int index=6;
imageView.image=[imageArray objectAtIndex:index];
NSLog(@"%@",[imageArray objectAtIndex:index]);

If I run this code I get (null) as an output...even though I have nicely put the images inside the array using the following code:

NSURL *url = [NSURL URLWithString:@"somelink"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
[imageArray addObject:image];

I am pretty sure there are 20 images (I use an XML file and print the URL and image) and the image is fine, too. I print the values of image before putting inside the array and here's the value I get is :

<UIImage: 0x5368670>

Can anyone kindly help me out ? Thanks.

2 Answers 2

1

Remember you'll need to make a new instance of the NSMutableArray... it's possible you're just calling methods on nil.

Before you start to you the imageArray, make sure you do something like:

imageArray = [NSMutableArray array]; 
// or      = [[NSMutableArray alloc] init]    if you want to "retain" it
//                                            for use in other methods
Sign up to request clarification or add additional context in comments.

Comments

0

Have you added at least seven such objects to the array, though? Remember that NSArray (and friends) count from zero, not one.

Also, are you certain that the object you're adding is not null (i.e, that dataWithContentsOfURL: and imageWithData: are both succeeding)?

1 Comment

I am sure. I am printing the value of image when I add them and a sample output is: <UIImage: 0x5368670>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.