Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 3.18 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. App crashes when UIImageView.image is set 2-3 times
  2. -(void)changeBgPictureTo:(UIImage *)img
  3. {
  4.     [self.backgroundImage setImage:img];
  5. }
  6.        
  7. [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
  8.        
  9. @interface MyImage : NSObject
  10. {
  11.     UIImage* image;
  12.     int imgId;
  13.     NSArray* colors; //contains 'UIColor' objects.
  14. }
  15.  
  16. @property (nonatomic, retain) UIImage* image;
  17. @property (nonatomic, retain) NSArray* colors;
  18. @property (nonatomic, readwrite) int imgId;
  19.  
  20. -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imgId andColors:(NSArray*)colorArray;
  21.  
  22. @end
  23.        
  24. -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imageId andColors:(NSArray*)colorArray
  25. {
  26.      self = [super init];
  27.  
  28.      if (self)
  29.      {
  30.          self.colors = [NSArray arrayWithArray:colorArray];
  31.          self.imgId = imageId;
  32.          self.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
  33.      }  
  34.  
  35. return self;
  36.        
  37. [self.myImages addObject:[[MyImage alloc] initWithFileName:[NSString stringWithFormat:@"0000%d", i] withType:@"jpg" andId:i andColors:colors]];
  38.        
  39. -(MyImage *)getImageWithId:(int)imgId
  40. {
  41.     for (MyImage* img in self.myImages)
  42.     {
  43.         if (img.imgId == imgId)
  44.             return img;
  45.     }
  46.     return nil;
  47. }
  48.        
  49. -(void)btnPushed:(id)sender
  50. {
  51.      [self.delegate changeBgPictureTo:[self.imgDataController getImageWithId:((UIButton*)sender).tag]];    
  52. }
  53.        
  54. -(void)changeBgPictureTo:(MyImage *)img
  55. {
  56.     NSLog(@"Setting image: %d", img.imgId);
  57.     [self.backgroundImage setImage:img.image];    
  58. }
  59.        
  60. @interface MyImage : NSObject
  61. {
  62.     NSString *fileName;//UIImage* image;
  63.     int imgId;
  64.     NSArray* colors; //contains 'UIColor' objects.
  65. }
  66.  
  67. @property (nonatomic, retain) NSString *fileName;//@property (nonatomic, retain) UIImage* image;
  68. @property (nonatomic, retain) NSArray* colors;
  69. @property (nonatomic, readwrite) int imgId;
  70.  
  71. -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imgId andColors:(NSArray*)colorArray;
  72.        
  73. -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imageId   andColors:(NSArray*)colorArray
  74. {
  75.      self = [super init];
  76.  
  77.      if (self)
  78.      {
  79.          self.colors = [NSArray arrayWithArray:colorArray];
  80.          self.imgId = imageId;
  81.          //self.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
  82.          self.fileName = [[NSBundle mainBundle] pathForResource:fileName ofType:type]];
  83.       }  
  84.       return self;
  85.  }
  86.        
  87. -(void)changeBgPictureTo:(MyImage *)img  
  88.  {
  89.     NSLog(@"Setting image: %d", img.imgId);
  90.     //[self.backgroundImage setImage:img.image];    
  91.     UIImage *img = [UIImage imageWithContentsOfFile:[img fileName]];
  92.     [self.backgroundImage setImage:img];
  93.  }
  94.        
  95. [self.myImages addObject:[[MyImage alloc] initWithFileName:[NSString stringWithFormat...
  96.        
  97. MyImage* img = [[MyImage alloc] initWithFileName:[NSString stringWithFormat...
  98. [self.myImages addObject:img];
  99. [img release];
  100.        
  101. [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImageName.png" ofType:nil]];