I want to toggle displaying an image in my program. Here is my code simplified:
UIImage *newImage = [UIImage imageNamed:@"selected.png"];
UIImageView *selector = [[UIImageView alloc] initWithImage: newImage];
[selector setFrame: CGRectMake( 0, 0, 64, 64)];
[overView addSubview: selector];
[overView bringSubviewToFront: selector];
selector.hidden = TRUE;
[newImage release]
Later in the code:
-(IBAction)Button1Click
{
selector.hidden = FALSE;
}
-(IBAction)Button2Click
{
selector.hidden = TRUE;
}
Later still:
[selector release];
When I run and click the two buttons the “selector” image never shows up. If I debug the program I can see the program reaches the lines under the IBActions, but it has no effect. Here is the strange thing: If I set the line early on to:
selector.hidden = FALSE;
Then I can see the “selected” image the whole time and it never turns off no matter what button I press. Any ideas?
UPDATE:
I know it was unclear in the code but “selector” is in the same scope in all the code. Adding “self.” to “selector” fixed the problem. Thank you!
from your code snippets it seems that you have property “selector” (accessed in IBActions) and local variable “selector” used in “main” snippet. If this is the case, you have to do something like this:
instead of