So, my app consists of a textview in one view controller. When the user taps a save button, the text from that textview is written to a plist with this code:
- (IBAction)saveDoc:(id)sender
{ NSString *typedText = typingArea.text; NSMutableArray *totalFiles = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedFiles.plist"];
[totalFiles addObject:typedText];
[totalFiles writeToFile:path atomically:YES];
[totalFiles release];
}
Then, in a totally separate view controller, I have a UITableView that displays the saved file using this code.:
- (void)viewDidLoad {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectories = [paths objectAtIndex:0];
NSString *path = [documentsDirectories stringByAppendingPathComponent:@"savedFiles.plist"];
NSLog(@"Got Path: %@", documentsDirectories);
array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSLog(@"Loaded Array into new array: %@", array);
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
array is an NSMutableArray. Then I load it into the table view like this:
// Configure the cell...
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
My question is, how do I make it so I can save multiple files and show multiple files in the table view. Right now, only one file can be saved and it is overwritten every time the save button is pressed.
Thanks in advance,
Tate