I loaded a number of images into an array in a ViewDidLoad method:
myImagesArray = [NSArray arrayWithObjects: [UIImage imageNamed"image1.jpg"], [UIImage imageNamed"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?
myImagesArray = [NSArray arrayWithObjects: [UIImage imageNamed"image1.jpg"], [UIImage imageNamed"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?