I’m trying to recall an image that I load in (void)viewDidLoad in another block, (void)moveObject. However, because I’m dealing with two different blocks, I apparently can’t recall the image. Is there some way I should rearrange the code to be able to make it work?
- (void)viewDidLoad {
CGRect myImageRect = CGRectMake(200.0f, 350.0f, 52.0f, 100.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"flake.png"]];
myImage.opaque = YES;
[self.view addSubview:myImage];
moveObjectTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(moveObject) userInfo:nil repeats:YES];
}
-(void) moveObject {
myImage.center = CGPointMake(myImage.center.x, myImage.center.y +1);
}
Create an instance variable for myImage, or a property if you’d like getters and setters as well.
Here’s how with just an instance variable:
.m