Can't get array declared
I want to make a simple picture display with a next button. I followe开发者_运维知识库d 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'?
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.
精彩评论