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]; }
source share