如何读取沙盒中的文件,和保存网络资源到沙盒中?
-(NSString *)dataFilePath:(NSString*)fileName
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *document=[paths objectAtIndex:0];
return [documentstringByAppendingPathComponent:fileName];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//可以下载图片
[self.datawriteToFile:[selfdataFilePath:@"image.jpg"]atomically:YES];
self.webView.hidden =YES;
//将沙盒中的图片加载到界面中
NSString *path = [selfdataFilePath:@"image.jpg"];
UIImage *imag = [[UIImagealloc]initWithContentsOfFile:path];
UIImageView *img = [[UIImageViewalloc]initWithImage:imag];
CGRect rect = CGRectMake(0,0,320,460);
img.frame = rect;
[self.viewaddSubview:img];

本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366414,如需转载请自行联系原作者