gpt4 book ai didi

ios - UIImageView setImage 不工作?

转载 作者:行者123 更新时间:2023-11-28 20:10:56 27 4
gpt4 key购买 nike

我有一个类,其中有两个 UIImageView。在 if control 之后我正在设置这些 ImageView 的图像,但它没有设置。

我正在调用另一个类的方法。

我的代码如下,

@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

我错过了什么?

请告诉我一个解决方案

最佳答案

使用这个方法并在你的 View Controller 类中添加一个观察者来观察图像对象的变化。当它通知时,您可以将图像对象放入 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;
}

关于ios - UIImageView setImage 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20299732/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com