Take the 2-minute tour ×

Quick help here please:-)

I have populated a UITableView with the contents of my Documents Directory and I can delete all the files with one button from the directory.

Now when I have deleted the files, the list of what the user sees still is the same and not until I reload the view will it show that indeed those files are gone.

I have used as per my code below:

[_mainTableView reloadData];
[_mainTableView beginUpdates]; & [_mainTableView endUpdates];

None of those are working, but I need the tableView to refresh once those files are gone.

        [_mainTableView beginUpdates];            
        NSFileManager *fileMgr = [[NSFileManager alloc] init];
        NSError *error = nil;

        NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:[self filePath] error:&error];
        NSLog(@"FILES - %@", directoryContents);

       if (error == nil) {
            for (NSString *path in _mainDataArray) {
                NSString *fullPath = [[self filePath] stringByAppendingPathComponent:path];
                BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
                if (!removeSuccess) {
                    // Error handling

                else if(removeSuccess)
                    [_mainTableView reloadData];
        [_mainTableView endUpdates];

Any other things I need to try??

share|improve this question
I'm not sure there's any reason for the begin and end updates. Try moving reloadData to outside your for-in loop. –  rdelmar Jan 30 '13 at 22:41
No that didn't work either sorry –  Jeff Kranenburg Jan 30 '13 at 22:44
add comment

2 Answers

up vote 0 down vote accepted

You're not emptying the array that populates your table. You're using the data in the array to delete items in the folder, but not removing items from the array, so, of course, the table is still populated.

share|improve this answer
Yeah I started to change of thinking and came to same conclusion as you explained - thanks:-) –  Jeff Kranenburg Jan 30 '13 at 22:51
The right way to do it is maybe to have reloadData load up the array, or at least somehow check if it needs to be reloaded. –  Hot Licks Jan 30 '13 at 22:56
add comment

I think you don't need to create a new instance of the NSFileManager; instead use:

[NSFileManager defaultManager];

The first if condition if (error == nil) will be true as error is nil and so I don't think it is going inside the for loop

share|improve this answer
No that didn't do it sorry –  Jeff Kranenburg Jan 30 '13 at 22:42
Remove that first if condition –  user427969 Jan 30 '13 at 22:45
add comment

Your Answer


