I am trying to save the text entered into a UITextField in a DetailView as a .txt file into the Documents Directory. I get the name of the .txt file from an NSMutableDictionary in a mainView which is a TableView.
Here is my code in the MainView;
In my DetailViewController I have this code to save the text;
I can input the text into the textfield and hit the button. The log shows the text being entered but I think I am not getting the 'key' from the dictionary the text can't be written to a txt file. It doesn't show up in the Document's Directory. I know that I could save this to NSUserDefault but I have my reasons why I don't want to. Can someone help me figure out how to access the Dictionary key?
Thanks
Here is my code in the MainView;
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
const NSDictionary *const row = [self rowForIndexPath:indexPath];
NSString *wantedClassName = [row objectForKey:@"controller"];
UIViewController *const vc = [[NSClassFromString (wantedClassName) alloc] init];
NSLog(@"controller is -%@-", wantedClassName);
if ([vc isKindOfClass:[DetailViewController class]])
{
DetailViewController *DetailView = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
**//This is where I think my problem is**
NSMutableDictionary *myDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"image.jpg",@"photokey",
@"name.txt", @"identity", nil];
DetailView.myDictionary = myDictionary;
}
[self.navigationController pushViewController:vc animated:YES];
}
In my DetailViewController I have this code to save the text;
Code:
-(IBAction)saveText:(id)sender
{
[self.name resignFirstResponder];
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *documentTXTPath = [documentsDirectory stringByAppendingPathComponent:[(NSMutableDictionary *)familyDictionary objectForKey:@"identity"]];
NSString *savedString = name.text;
NSLog(@"The Save file is:%@", savedString);
[savedString writeToFile:documentTXTPath atomically:YES
encoding:NSUTF8StringEncoding error:NULL];
}
I can input the text into the textfield and hit the button. The log shows the text being entered but I think I am not getting the 'key' from the dictionary the text can't be written to a txt file. It doesn't show up in the Document's Directory. I know that I could save this to NSUserDefault but I have my reasons why I don't want to. Can someone help me figure out how to access the Dictionary key?
Thanks