Guest User

Untitled

a guest
Jun 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. @interface SomeViewController : UIViewController
  2. {
  3. UIImageView *imgView;
  4. }
  5.  
  6. imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen]
  7. applicationFrame]];
  8. [imgView setImage:[UIImage imageNamed:@"someimage.png"]];
  9. [self addSubview:imgView];
  10. [imgView release];
  11.  
  12. - (void) dealloc
  13. {
  14. [imgView release];
  15. [super dealloc];
  16.  
  17. }
  18.  
  19. @interface SomeViewController : UIViewController
  20. {
  21. UIImageView *imgView;
  22. }
  23. @property (nonatomic, retain) UIImageView *imgView;
  24.  
  25. @synthesize imgView;
  26.  
  27. //Create a new image view object and store it in a local variable (retain count 1)
  28. UIImageView *newImgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
  29. newImgView.image = [UIImage imageNamed:@"someimage.png"];
  30.  
  31. //Use our property to store our new image view as an instance variable,
  32. //if an old value of imgView exists, it will be released by generated method,
  33. //and our newImgView gets retained (retain count 2)
  34. self.imgView = newImgView;
  35.  
  36. //Release local variable, since the new UIImageView is safely stored in the
  37. //imgView instance variable. (retain count 1)
  38. [newImgView release];
  39.  
  40. //Add the new imgView to main view, it's retain count will be incremented,
  41. //and the UIImageView will remain in memory until it is released by both the
  42. //main view and this controller. (retain count 2)
  43. [self.view addSubview:self.imgView];
  44.  
  45. - (void) dealloc
  46. {
  47. [imgView release];
  48. [super dealloc];
  49. }
  50.  
  51. self.imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen]
Add Comment
Please, Sign In to add comment