objective c - NSCFType keeps occurring, something is not being released? -
i'm attempting delete files documents directory using tableview/array combination. reason, nsstring
pointing documents directory path being converted nscftype
(which after research, understand happening because variable not being released). because of this, application crashes @ line
nsstring *lastpath = [documentsdirectory stringbyappendingpathcomponent:temp];
claiming nscftype
cannot recognize method stringbyappendingpathcomponent
.
i appreciate if me out (i hope have explained enough).
- (void) tableview: (uitableview *) tableview commiteditingstyle: (uitableviewcelleditingstyle) editingstyle forrowatindexpath: (nsindexpath *) indexpath { if (editingstyle == uitableviewcelleditingstyledelete) { nsstring *temp = [directorycontent objectatindex:indexpath.row]; nslog(temp); nsstring *lastpath = [documentsdirectory stringbyappendingpathcomponent:temp]; [[nsfilemanager defaultmanager] removeitematpath:lastpath error:nil];
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); documentsdirectory = [paths objectatindex:0]; directorycontent = [[[nsfilemanager defaultmanager] contentsofdirectoryatpath:documentsdirectory error:nil] retain]; //tableview handling below }
it seems documentsdirectory
being set autoreleased object fix that,
you either retain it
documentsdirectory = [[paths objectatindex:0] retain];
or initialize before using each time this
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); documentsdirectory = [paths objectatindex:0]; nsstring *lastpath = [documentsdirectory stringbyappendingpathcomponent:temp]; [[nsfilemanager defaultmanager] removeitematpath:lastpath error:nil];
my advice, dont add these variable instance variable, dont need to, better creating them whenever need them
Comments
Post a Comment