I’m attempting to delete files from the documents directory using a tableview/array combination.
For some reason, my NSString pointing to the Documents directory path is being converted to a NSCFType (which after some research, I understand is happening because a variable is not being released). Because of this, the application crashes at the line
NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:temp];
claiming that NSCFType cannot recognize the method stringByAppendingPathComponent.
I would appreciate if someone could help me out (I hope I have explained this clearly 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 that
documentsDirectoryis being set to an autoreleased object to fix that,You either retain it
Or you initialize it just before using it each time like this
My advice, dont add all these variable as instance variable, you dont need to, its better creating them whenever you need them