私はキャッシュイメージと呼ばれる方法を持っています。これは、NSNotification センターを使用して、画像がキャッシュされたという情報を投稿します。データ NSMutableDictionary *userInfo があります。オブザーバーを追加して画像を取得し、_URL をキーとして保存しようとしています。問題は、URL と画像の両方が、独自のキーを持つオブジェクトとして辞書に追加されることです。対応するキーの画像を取得できますか?
- (void)cacheImage:(UIImage *)image
{
if (!_cancelled)
{
if (image && _URL)
{
BOOL storeInCache = YES;
if ([_URL isFileURL])
{
if ([[[_URL absoluteURL] path] hasPrefix:[[NSBundle mainBundle] resourcePath]])
{
//do not store in cache
storeInCache = NO;
}
}
if (storeInCache)
{
[_cache setObject:image forKey:_URL];
}
}
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
image, AsyncImageImageKey,
_URL, AsyncImageURLKey,
nil];
NSLog(@"%@",_URL);
if (_cache)
{
[userInfo setObject:_cache forKey:AsyncImageCacheKey];
}
_loading = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:AsyncImageLoadDidFinish
object:_target
userInfo:[[userInfo copy] autorelease]];
}
else
{
_loading = NO;
_cancelled = NO;
}
}
私の他のクラスのviewcontroller.mファイルで
-(void)ViewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(imageLoaded:)
name:AsyncImageLoadDidFinish
object:nil];
}
- (void)imageLoaded:(NSNotification *)notification
{
NSMutableDictionary *imageCache = notification.object;// help needed here
}
オブザーバーを追加しようとしていますが、オブジェクト「_URL」を画像のキーとして使用する方法がわかりません。オブザーバーを使用してオブジェクトを受け取った後、その URL の画像キャッシュを見つける必要があります。