редактировать таблицуПросмотреть и удалить файл документа - PullRequest
0 голосов
/ 25 января 2012

У меня есть tabBarController с 4 viewController.Одним из них является TableViewController.В viewDidLoad tableView я инициализирую 2 NSMutableArray

list = [[NSMutalbeArray alloc] init];
dates = [[NSMutalbeArray alloc] init];

в viewDidAppear я добавляю объекты

NSError *error;
NSError *error1;
fileManager = [NSFileManager defaultManager];
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
docsPath = [paths objectAtIndex:0]; 
for (NSString *file in [fileManager contentsOfDirectoryAtPath:docsPath error:&error]) {
    fileFrom = [docsPath stringByAppendingPathComponent:file];
    NSDictionary* properties = [[NSFileManager defaultManager]
                                attributesOfItemAtPath:fileFrom
                                error:&error1];
    NSDate* modDate = [properties objectForKey:NSFileModificationDate];        
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    
    [dateFormatter setLocale: [NSLocale currentLocale]];    
    [dateFormatter setDateStyle:kCFDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:kCFDateFormatterNoStyle];   
    NSString* dateString = [dateFormatter stringFromDate:modDate];
    BOOL isDir;
    BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", docsPath, file] isDirectory:&isDir];
    if (exists && !isDir && ![file hasPrefix:@"."]) {
        [list addObject:file];
        [dates addObject:dateString];
    }
}
[[self tableView] reloadData];    

, где каждый файл - это имя файла в моем documentDirectory и dateString дата создания.

Я могу визуализировать в моем tableView список файлов.

Если я отредактирую tableView и попытаюсь удалить элемент, он работает, я могу удалить элемент как из файловой системы, так и из tableView, НО, если я добавлюновый файл в папку с документами (как и приложения) я получаю EXE_BAD_ADDRESS

- (void)tableView:(UITableView *)tableView commitEditingStyle:    (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
    NSString *temp = [list objectAtIndex:indexPath.row];
    NSString *lastPath = [docsPath stringByAppendingPathComponent:temp];
    [fileManager removeItemAtPath:lastPath error:nil];
    [self.list removeObjectAtIndex:indexPath.row];
    [self.dates removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];

        [self.tableView reloadData];
   }   
}

Любой совет?

...