Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nraygun

macrumors newbie
Original poster
May 9, 2005
20
0
I loaded a number of images into an array in a ViewDidLoad method:
myImagesArray = [NSArray arrayWithObjects: [UIImage imageNamed:mad:"image1.jpg"], [UIImage imageNamed:mad:"image2.jpg"], etc., nil];

If I set the image of my view in this same method with this:
myImageView.image = [myImagesArray objectAtIndex:1];

it works.

If I do this last statement elsewhere in the same object I get a crash:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (0)'

If it works in one area(inside of ViewDidLoad) why doesn't it work in another area? I thought the scope of variables was across all methods in a class.

What am I doing wrong?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Is the array retained in any way? Arrays created by any method other than alloc/new/copy/mutable copy are all autoreleased and without retaining them they are prone to vanishing at any time.
 

Nraygun

macrumors newbie
Original poster
May 9, 2005
20
0
That's probably it.

So I just need to throw one of these in, right?

[myImagesArray retain];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.