如何检查设置了图像的URL?

问题描述 投票:0回答:1

我使用image这样设置url

[self.imageView setMyImageWithURL:[NSURL URLWithString:[trip.destination getHeaderImageUrl] ]];
- (void)setMYImageWithURL:(NSURL *)url {
    [self setBackground];

    if(url.absoluteString.length >0){
        __block UIImageView *safeSelf = self;
        UIImage *placeholderImage = [UIImage imageNamed:[NSString stringWithFormat:@"placeholderpic_%@.png", NSLocalizedString(@"LanguageCode" , @"")]];
        [self setImageWithURLRequest:[NSURLRequest requestWithURL:url]
                    placeholderImage:placeholderImage
                             success:nil
                             failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
                                 safeSelf.image = [UIImage imageNamed:[NSString stringWithFormat:@"placeholderpic_%@_missing.png", NSLocalizedString(@"LanguageCode" , @"")]];
                             }
         ];
    }else{
        self.image = [self missingImage];
    }
}

现在,可以在设置imageView url之后检查它。像NSLog(@"%@", self.imageView.usingURL)。我想检查它是否与使用条件的另一个url相同。像这样:

if(self.imageView.usingURL == [NSURL URLWithString:[trip.destination getHeaderImageUrl]])
ios objective-c url uiimage
1个回答
1
投票

使用此类别在UIImageView中添加属性

@interface UIImageView (URLImageView)
    @property NSURL* usingURL;
@end

@implementation UIImageView (URLImageView)]
@end

现在下载图像并设置为图像视图时,将URL分配给图像视图,如

self.imageView.usingURL = yourURL

现在您可以访问此URL进行比较。

© www.soinside.com 2019 - 2024. All rights reserved.