How to create an instance variable in Objective-C

I have this example, and I would like to make my_Picture an instance variable in order to use removeFromView. Any ideas? I received all kinds of warnings and errors, trying to use different approaches. Thank you in advance

- (void) viewDidLoad { UIImageView *my_Picture = [[UIImageView alloc] initWithImage: myImageRef]; [self.view addSubview:my_Picture]; [my_Picture release]; [super viewDidLoad]; } 
+4
source share
1 answer

To make this an instance variable, you store the value in your class instead of a temporary variable. You will also release it when your class is destroyed, and not after adding it as a preview.

eg.

 // header file (.h) @interface MyController : UIViewController { UIImageView* myPicture; } @end // source file (.m) - (void) viewDidLoad { myPicture = [[UIImageView alloc] initWithImage: myImageRef]; [self.view addSubview:myPicture]; [super viewDidLoad]; } - (void) dealloc { [myPicture release]; [super dealloc]; } 
+9
source

All Articles