PTC
PTC

Reputation: 199

Populate UITableView with list of files from Documents Directory in iPhone SDK 5.0

I am developing for iOS 5. What I would like to do is read the list of files in my app's Documents Directory and list them in the UITableView. I found an article on StackOverflow, but the API's used have been deprecated. Any ideas on what to do here?

Upvotes: 1

Views: 2344

Answers (1)

WrightsCS
WrightsCS

Reputation: 50727

You can insert the files of the directory into an NSArray and list them in the cells like this:

cellForRowAtIndexPath:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileListAct = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];

cell.textLabel.text = NSString stringWithFormat:@"%@",[fileListAct objectAtIndex:indexPath.row]];

This still works in iOS5 and has not been deprecated.

Upvotes: 2

Related Questions