0
我正在创建一个图像库,点击图像可导航到下一个视图。我正在使用SDWebImage库来缓存图像。缓存工作得很好,我正在获取图像库。问题是,如果我清除缓存并运行我的应用程序。iPad上的SDWebImage
图像被下载到委托方法中,但我无法在我的按钮(viewdidload中的dat)中分配下载的图像,第一次也没有发生缓存,并且图像只有在第二次运行我的iPad应用程序时才会显示(由于缓存)。我想要在清除缓存时下载并显示图像。我怎样才能做到这一点?
我甚至准备给整个源代码。
- (void)viewDidLoad {
[super viewDidLoad];
self.synced = [NSMutableArray array];
[email protected]"boom";
jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephenFlickr.json"];
jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl];
dict=[jsonData objectFromJSONString];
items=[dict objectForKey:@"items"];
story = [[NSMutableArray array]retain];
media1= [[NSMutableArray array]retain];
for (NSDictionary *item in items)
{
[story addObject:[item objectForKey:@"title"]];
[media1 addObject:[item objectForKey:@"media"]];
}
view1 = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
for(int i = 0; i < media1.count; i++)
{
NSString *mel=[media1 objectAtIndex:i];
NSString *escapedURL = [mel stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url1=[NSURL URLWithString:escapedURL];
managaer=[SDWebImageManager sharedManager];
cacheImage = [managaer imageWithURL:url1];
//To clear the cache, uncomment these three lines
/* SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache clearDisk];
[imageCache clearDisk];*/
if (cacheImage) {
//If a cache image is present
}
else
{ //If there is no cache image present, download.
[managaer downloadWithURL:url1 delegate:self];
}
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*260+1, row*280+300, 250, 250);
[button setImage:cacheImage forState:UIControlStateNormal];
NSLog(@"cached image:%@",cacheImage);
[button addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[view1 addSubview:button];
if (column == 2) {
column = 0;
row++;
} else {
column++;
}
}
[view1 setContentSize:CGSizeMake(600, (row+1) *280 + 10)];
[self.view addSubview:view1];
[view1 release];
}
-(void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage: (UIImage *)image
{
//The image gets downloaded over here..
}
mkay会试一试 – kingston
我尝试在webImageManager中粘贴整个for循环:didFinishWithImage离开委托调用,它是“[managaer downloadWithURL:url1 delegate:self];”在viewdidload..the-webImageManager:didFinishWithImage没有得到调用...我会粘贴我的整个代码上面..你帮我 – kingston