- App crashes when UIImageView.image is set 2-3 times
- -(void)changeBgPictureTo:(UIImage *)img
- {
- [self.backgroundImage setImage:img];
- }
- [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
- @interface MyImage : NSObject
- {
- UIImage* image;
- int imgId;
- NSArray* colors; //contains 'UIColor' objects.
- }
- @property (nonatomic, retain) UIImage* image;
- @property (nonatomic, retain) NSArray* colors;
- @property (nonatomic, readwrite) int imgId;
- -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imgId andColors:(NSArray*)colorArray;
- @end
- -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imageId andColors:(NSArray*)colorArray
- {
- self = [super init];
- if (self)
- {
- self.colors = [NSArray arrayWithArray:colorArray];
- self.imgId = imageId;
- self.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
- }
- return self;
- [self.myImages addObject:[[MyImage alloc] initWithFileName:[NSString stringWithFormat:@"0000%d", i] withType:@"jpg" andId:i andColors:colors]];
- -(MyImage *)getImageWithId:(int)imgId
- {
- for (MyImage* img in self.myImages)
- {
- if (img.imgId == imgId)
- return img;
- }
- return nil;
- }
- -(void)btnPushed:(id)sender
- {
- [self.delegate changeBgPictureTo:[self.imgDataController getImageWithId:((UIButton*)sender).tag]];
- }
- -(void)changeBgPictureTo:(MyImage *)img
- {
- NSLog(@"Setting image: %d", img.imgId);
- [self.backgroundImage setImage:img.image];
- }
- @interface MyImage : NSObject
- {
- NSString *fileName;//UIImage* image;
- int imgId;
- NSArray* colors; //contains 'UIColor' objects.
- }
- @property (nonatomic, retain) NSString *fileName;//@property (nonatomic, retain) UIImage* image;
- @property (nonatomic, retain) NSArray* colors;
- @property (nonatomic, readwrite) int imgId;
- -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imgId andColors:(NSArray*)colorArray;
- -(id)initWithFileName:(NSString*)fileName withType:(NSString*)type andId:(int)imageId andColors:(NSArray*)colorArray
- {
- self = [super init];
- if (self)
- {
- self.colors = [NSArray arrayWithArray:colorArray];
- self.imgId = imageId;
- //self.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:type]]];
- self.fileName = [[NSBundle mainBundle] pathForResource:fileName ofType:type]];
- }
- return self;
- }
- -(void)changeBgPictureTo:(MyImage *)img
- {
- NSLog(@"Setting image: %d", img.imgId);
- //[self.backgroundImage setImage:img.image];
- UIImage *img = [UIImage imageWithContentsOfFile:[img fileName]];
- [self.backgroundImage setImage:img];
- }
- [self.myImages addObject:[[MyImage alloc] initWithFileName:[NSString stringWithFormat...
- MyImage* img = [[MyImage alloc] initWithFileName:[NSString stringWithFormat...
- [self.myImages addObject:img];
- [img release];
- [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"yourImageName.png" ofType:nil]];