Reputation: 1721
I have a class in which i have two UIImageViews. After if control i am setting the image of these ImageView but it is not set.
I am calling the method from another class.
My code is as below,
@synthesize coordinate, title, subtitle,number,index,vstd,sold;
NSString *identifier;
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self != nil)
{
UIImageView * ecz = [[UIImageView alloc]init];
ecz.frame = CGRectMake(0, 0, 87, 50);
ecz.image = [STCachedImage getCachedImage:@"eczane_indicator"];
[self addSubview:ecz];
[ecz release];
vstd = [[UIImageView alloc]initWithFrame:CGRectMake(8, 10, 25, 22)];
[self addSubview:vstd];
[vstd release];
sold = [[UIImageView alloc]initWithFrame:CGRectMake(50, 10, 25, 22)];
[self addSubview:sold];
[sold release];
}
return self;
}
-(void) visitOrderFlag : (NSString*)visitFlag withOrderFlag:(NSString*)orderFlag
{
if([visitFlag isEqualToString:@"0"])
{
UIImage *visitedImage = [STCachedImage getCachedImage:@"pharm1"];
[vstd setImage:visitedImage];
}
else
{
UIImage *visitedPressedImage = [STCachedImage getCachedImage:@"pharm2"];
[vstd setImage:visitedPressedImage];
}
if([orderFlag isEqualToString:@"0"])
{
UIImage *orderedImage = [STCachedImage getCachedImage:@"pharm3"];
[sold setImage:orderedImage];
}
else
{
UIImage *orderedPressedImage = [STCachedImage getCachedImage:@"pharm4"];
[sold setImage:orderedPressedImage];
}
}
@end
What am i missing?
Please show me a solution
Upvotes: 0
Views: 1732
Reputation: 857
use this method and and add a observer in your view controller class to observe change in image object . When it notifies then you can put your image object into UIimageView.
-(UIImage *)thumbImage{
__block UIImage *myImage;
if([[NSFileManager defaultManager] fileExistsAtPath:[Utility systemFilePath:imageURL_]]) {
NSData *imageData = [NSData dataWithContentsOfFile:[Utility systemFilePath:imageURL_]];
if (imageData != nil) {
dealImage = [UIImage imageWithData:imageData];
}
}
else{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Load image in background
NSData* imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString: dealImageURL_]];
dispatch_async(dispatch_get_main_queue(), ^{
myImage = [UIImage imageWithData:imgData];
if(myImage){
NSString *filePathToSave = [Utility systemFilePath:imageURL_];
if (filePathToSave) {
[self willChangeValueForKey:@"profileImage"];
[imgData writeToFile:filePathToSave atomically:YES];
[self didChangeValueForKey:@"profileImage"];
}
}
});
});
}
return myImage;
}
Upvotes: 2
Reputation: 857
*ecz.image = [STCachedImage getCachedImage:@"eczane_indicator"];
This Method getchachedImage took time , and you are releasing the image view after that.
Upvotes: 1