0

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?

0

2 Answers 2

1

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];
}
Sign up to request clarification or add additional context in comments.

1 Comment

That is exactly it, I never retained it, so I lost if when the function exited. Thanks a lot for this. :)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.