开发者

problem with accessing NSMutableArray

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 su开发者_开发技巧re 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.


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


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)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜