in my project i have 9 pictures. i load each picture into an nsmutablearray so that when another method is called, a new image is displayed.
here is the method that populates the nsmutablearray
this loads the array correctly, the array count is 9 which is correct and the retain count is 1, also correct.
here is the method that access the images in the array
but now, and i don't know why, the retain count is 0, the if statement always returns false (obviously if retain count is 0) and the image doesn't change.
could someone tell me what is going on here, why is my array's retain count 0? I cant use any images in the array.
thanks for your help
here is the method that populates the nsmutablearray
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
foodImage.image = [UIImage imageNamed:@"hamburger.jpg"];
imageArray = [[NSMutableArray alloc] init];
for(int i = 1; i < 10; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat: @"bite-%d.jpg", i]];
[imageArray addObject:image];
[image release];
}
NSLog(@"array count %d", [imageArray count]);
NSLog(@"array retain count: %d", [imageArray retainCount]);
}
this loads the array correctly, the array count is 9 which is correct and the retain count is 1, also correct.
here is the method that access the images in the array
Code:
-(void)takeBite:(int)biteNumber
{
NSLog(@"array retain count: %d", [imageArray retainCount]);
UIImage *tempPic = [imageArray objectAtIndex: biteNumber];
if (tempPic)
{
NSLog(@"if statement true");
foodImage.image = tempPic;
}
}
but now, and i don't know why, the retain count is 0, the if statement always returns false (obviously if retain count is 0) and the image doesn't change.
could someone tell me what is going on here, why is my array's retain count 0? I cant use any images in the array.
thanks for your help