Solved.
If you want to retain the elements in an NSArray across functions then you have to pass it the retain message.
1. So in Header file I have :
NSArray *imageArray;
2. In Implementation I have this inside "viewDidLoad()"
imageArray = [[NSArray arrayWithObjects:
[UIImage imageNamed:@"01.JPG"],
[UIImage imageNamed:@"02.JPG"],
[UIImage imageNamed:@"03.JPG"],
[UIImage imageNamed:@"04.JPG"],
nil] retain];
3. notice the retain message that gets passed to NSArray. This makes sure the objects are persistent in memory and available when "imageArray" is accessed in other functions.
4. without the retain message, the objects are released in viewDidLoad() and trying to access the array elements in another function will result in a crash.
|