0

I want to make a simple picture display with a next button. I followed this code:

NSArray *pics2;
pics2=[[NSArray alloc] initWithObjects:

      [UIImage imageNamed:@"1.jpg"],
      [UIImage imageNamed:@"2.jpg"],
      [UIImage imageNamed:@"3.jpg"],
      [UIImage imageNamed:@"4.jpg"],
      [UIImage imageNamed:@"5.jpg"],
      [UIImage imageNamed:@"6.jpg"],
      [UIImage imageNamed:@"7.jpg"],
      [UIImage imageNamed:@"8.png"],
      [UIImage imageNamed:@"9.jpg"],
      nil
      ];
NSLog(@"%i",[pics2 count]);
for (int i=0;i<[pics2 count]; i++){
    [foto setImage:[pics2 objectAtIndex:i]];
}
[pics2 release];

And then after the @synthesize the IBAction.

-(IBAction) prox:(id)sender {

 static int i=0;
 if(i==8)
     i=0;
 [foto setImage:[pics2 objectAtIndex:i]];

But I'm getting the error "Use of undeclared identifier 'pics2'. Where am I supposed to declare the array 'pics2'?

1 Answer 1

1

You are releasing pics2 before using it. If you want pics2 to be available to all functions of your class then make it as a private variable in the header file.

Define the NSArray *pics2; in the .h file. Don't release it after creating, release it only in the dealloc method.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, so I declared and it worked for the first click, not for the followings.
I wonder if the NSLog is in the correct place. Shouldn't it be on the Action of the button?
maybe you can check if the value of i is getting updated. I think from your code, i will always be 0 in the IBAction method
Daniel, you appear to be setting the animation images in your init method already ([foto setImage:[pics2 objectAtIndex:i]], in your for loop). But then in your event handler method you are setting it again using a static counter that you never increment. If you could state what you are trying to achieve we could help with the logic.

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.