Reputation: 29886
In class1 I create an object of class2. I then use a method on this object to set its NSMutableArray
-(void) cloneArray: (NSMutableArray *) array{
pictures = [NSMutableArray arrayWithArray:array];
}
Class2 is a ViewController which has a UIImageView.
I present the class2 object after creating it. This class then has its own methods which display the next image when a swipe is detected.
-(void) nextImageSelector{
if (counter == [pictures count]-1) {
counter = 1;
asset = [pictures objectAtIndex:counter];
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];
UIImage *fullScreenImage = [UIImage imageWithCGImage:[assetRepresentation fullScreenImage] scale:[assetRepresentation scale] orientation:[assetRepresentation orientation]];
photo.image = fullScreenImage;
}
The app crashes when calling the line
if (counter == [pictures count]-1)
So I think it is crashing because the array is created for an object and then the next array is trying to be checked is for the class instance itself.
How can I fix this so that I can copy an array for this class2 to use in its own methods like the nextImageSelector?
Upvotes: 0
Views: 180
Reputation: 8383
I think u are getting this problem because u are loosing the acces of the array try using, as it is accessor method.
-(void)cloneArray: (NSMutableArray *) array
{
pictures = [[NSMutableArray arrayWithArray:array] retain];
}
Upvotes: 1
Reputation: 5057
Use NSZombiesEnabled
to find out if your NSMutableArray
gets deallocated. Have you checked your memory management? Run Build & Analyze could also help.
What kind of crash do you see?
In your cloneArray
method the pictures array is not retained. You have to retain it in Class2 and make sure to release it once you are done with it in class 2's dealloc
method.
Upvotes: 0