Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何改进图像加载问题。有没有类似缓存的解决方案_Iphone_Ios_Objective C_Parse Platform - Fatal编程技术网

Iphone 如何改进图像加载问题。有没有类似缓存的解决方案

Iphone 如何改进图像加载问题。有没有类似缓存的解决方案,iphone,ios,objective-c,parse-platform,Iphone,Ios,Objective C,Parse Platform,我使用Parse.com构建了一个iOS应用程序 在我的应用程序中,我显示了许多来自网络的数据 为了快速加载数据,我使用了cachekpfcachepolicycachetennetwork。它可以很好地加载数据,但在滚动图像时需要花费一些时间来加载。 首先加载白色图像,然后加载图像 有没有像缓存这样的解决方案可以在ImageView中显示图像而不中断。 谢谢。这是在后台加载图像的代码。选中此项以下是在后台加载图像的代码。选中此复选框,您可以使用它来执行此操作 也可以用于缓存目的。您可以使用 您

我使用Parse.com构建了一个iOS应用程序

在我的应用程序中,我显示了许多来自网络的数据

为了快速加载数据,我使用了cache
kpfcachepolicycachetennetwork
。它可以很好地加载数据,但在滚动图像时需要花费一些时间来加载。

首先加载白色图像,然后加载图像

有没有像缓存这样的解决方案可以在ImageView中显示图像而不中断。


谢谢。

这是在后台加载图像的代码。选中此项

以下是在后台加载图像的代码。选中此复选框,您可以使用它来执行此操作

也可以用于缓存目的。

您可以使用

您还可以用于缓存目的。

是的,您可以使用UIImageview类别并进行排序

如果编辑现有图像,然后通过操纵其URL从同一URL加载,则还可以禁用通常需要的特定图像的缓存

-(void)setImageWithURL:(NSURL *)url
       placeholderImage:(UIImage *)placeholderImage
如本文所述

另一个选项可以是刷新缓存的工具。

是的,您可以使用UIImageview类别并对其进行排序

如果编辑现有图像,然后通过操纵其URL从同一URL加载,则还可以禁用通常需要的特定图像的缓存

-(void)setImageWithURL:(NSURL *)url
       placeholderImage:(UIImage *)placeholderImage
如本文所述


另一个选项是使用刷新缓存的工具。

我在gcd的帮助下编写代码,您只需传递imageView的对象和url,它管理所有事情,比如缓存

-(void)downloadingServerImageFromUrl:(UIImageView*)imgView AndUrl:(NSString*)strUrl{


strUrl = [strUrl encodeUrl];

NSString* theFileName = [NSString stringWithFormat:@"%@.png",[[strUrl lastPathComponent] stringByDeletingPathExtension]];


NSFileManager *fileManager =[NSFileManager defaultManager];

NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]];



imgView.backgroundColor = [UIColor darkGrayColor];
UIActivityIndicatorView *actView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[imgView addSubview:actView];
[actView startAnimating];

CGSize boundsSize = imgView.bounds.size;
CGRect frameToCenter = actView.frame;
// center horizontally
if (frameToCenter.size.width < boundsSize.width)
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
else
frameToCenter.origin.x = 0;




 // center vertically
if (frameToCenter.size.height < boundsSize.height)
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
else
frameToCenter.origin.y = 0;

actView.frame = frameToCenter;



dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{

NSData *dataFromFile = nil;
NSData *dataFromUrl = nil;

dataFromFile = [fileManager contentsAtPath:fileName];
if(dataFromFile==nil){
    dataFromUrl=[[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strUrl]] autorelease];                      
}

dispatch_sync(dispatch_get_main_queue(), ^{

    if(dataFromFile!=nil){
        imgView.image = [UIImage imageWithData:dataFromFile];
    }else if(dataFromUrl!=nil){
        imgView.image = [UIImage imageWithData:dataFromUrl];  
        NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]];

        BOOL filecreationSuccess = [fileManager createFileAtPath:fileName contents:dataFromUrl attributes:nil];       
        if(filecreationSuccess == NO){
            NSLog(@"Failed to create the html file");
        }

    }else{
        imgView.image = [UIImage imageNamed:@"NO_Image.png"];  
    }
    [actView removeFromSuperview];
    [actView release];
    [imgView setBackgroundColor:[UIColor clearColor]];
});
});
-(void)下载ServerImageFromURL:(UIImageView*)imgView和URL:(NSString*)strUrl{
strUrl=[strUrl encodeUrl];
NSString*theFileName=[NSString stringWithFormat:@“%@.png”,[[strUrl lastPathComponent]stringByDeletingPathExtension];
NSFileManager*fileManager=[NSFileManager defaultManager];
NSString*文件名=[NSHomeDirectory()stringByAppendingPathComponent:[NSString stringWithFormat:@“tmp/%@”,文件名]];
imgView.backgroundColor=[UIColor darkGrayColor];
UIActivityIndicatorView*actView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[imgView添加子视图:actView];
[actView startAnimating];
CGSize boundsSize=imgView.bounds.size;
CGRect frameToCenter=actView.frame;
//水平居中
if(frameToCenter.size.width

}

我在gcd的帮助下编写代码,您只需传递imageView的对象和url,它管理所有的事情,比如缓存

-(void)downloadingServerImageFromUrl:(UIImageView*)imgView AndUrl:(NSString*)strUrl{


strUrl = [strUrl encodeUrl];

NSString* theFileName = [NSString stringWithFormat:@"%@.png",[[strUrl lastPathComponent] stringByDeletingPathExtension]];


NSFileManager *fileManager =[NSFileManager defaultManager];

NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]];



imgView.backgroundColor = [UIColor darkGrayColor];
UIActivityIndicatorView *actView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[imgView addSubview:actView];
[actView startAnimating];

CGSize boundsSize = imgView.bounds.size;
CGRect frameToCenter = actView.frame;
// center horizontally
if (frameToCenter.size.width < boundsSize.width)
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
else
frameToCenter.origin.x = 0;




 // center vertically
if (frameToCenter.size.height < boundsSize.height)
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
else
frameToCenter.origin.y = 0;

actView.frame = frameToCenter;



dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{

NSData *dataFromFile = nil;
NSData *dataFromUrl = nil;

dataFromFile = [fileManager contentsAtPath:fileName];
if(dataFromFile==nil){
    dataFromUrl=[[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strUrl]] autorelease];                      
}

dispatch_sync(dispatch_get_main_queue(), ^{

    if(dataFromFile!=nil){
        imgView.image = [UIImage imageWithData:dataFromFile];
    }else if(dataFromUrl!=nil){
        imgView.image = [UIImage imageWithData:dataFromUrl];  
        NSString *fileName = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"tmp/%@",theFileName]];

        BOOL filecreationSuccess = [fileManager createFileAtPath:fileName contents:dataFromUrl attributes:nil];       
        if(filecreationSuccess == NO){
            NSLog(@"Failed to create the html file");
        }

    }else{
        imgView.image = [UIImage imageNamed:@"NO_Image.png"];  
    }
    [actView removeFromSuperview];
    [actView release];
    [imgView setBackgroundColor:[UIColor clearColor]];
});
});
-(void)下载ServerImageFromURL:(UIImageView*)imgView和URL:(NSString*)strUrl{
strUrl=[strUrl encodeUrl];
NSString*theFileName=[NSString stringWithFormat:@“%@.png”,[[strUrl lastPathComponent]stringByDeletingPathExtension];
NSFileManager*fileManager=[NSFileManager defaultManager];
NSString*文件名=[NSHomeDirectory()stringByAppendingPathComponent:[NSString stringWithFormat:@“tmp/%@”,文件名]];
imgView.backgroundColor=[UIColor darkGrayColor];
UIActivityIndicatorView*actView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[imgView添加子视图:actView];
[actView startAnimating];
CGSize boundsSize=imgView.bounds.size;
CGRect frameToCenter=actView.frame;
//水平居中
if(frameToCenter.size.width