ios - displaying image in table view which is saved in document directory -
i have saved image in document directory following code , after image there in documentary directory
uiimage *image =[[uiimage alloc ]init ]; image = [uiimage imagenamed:@"placeholder.png"]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring* path = [documentsdirectory stringbyappendingpathcomponent:[nsstring stringwithstring: @"placeholder.png"] ]; nsdata* data = uiimagepngrepresentation(image); [data writetofile:path atomically:yes];
now want display image in table view in table view images getting displayed facebook url thats why using following code
nsstring *path = [[_arrayfortable valueforkey:@"url"] objectatindex:[indexpath row]]; nsurl *url = [nsurl urlwithstring:path]; asyncimageview *imageview = [[[asyncimageview alloc] init] autorelease]; imageview.frame = cgrectmake(0, -5, 45, 45); imageview.imageurl=url;
_arrayfortable array of dic , includes url links facebook , document directory
now problem follows
** facebook images getting displayed in table view document directory images not getting displayed**
i have checked location correct image displaying
nsurl *url = [nsurl urlwithstring:path];
this wrong in code. replace line of code.
nsurl *url = [nsurl fileurlwithpath:path];
check if file exists in documents directory or not
if([[nsfilemanager defaultmanager] fileexistsatpath:path]) nsurl *url = [nsurl fileurlwithpath:path];
also check in documents directory if image getting saved or not. given name of image this
image = [uiimage imagenamed:@"placeholder.png"];
so if repeating line images overwritten in documents directory.
you can put check here bool success = [data writetofile:path atomically:yes];
if(success) nslog(@"image written successfully"); else nslog(@"image writing failed");
hope helped.
Comments
Post a Comment