如何讀取沙盒中的檔案,和儲存網絡資源到沙盒中?
-(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,如需轉載請自行聯系原作者