I have searched everywhere and tried lots of code but nothing seems to be working for me. All I need to do is to load (on viewDidLoad) a text field and save it when a button is
Create a NSMutableDictionary as property and ...
when your button is clicked:
-(IBAction)buttonClicked:(id)sender
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *devicePath = [documentsDirectory stringByAppendingPathComponent:@"yourfile.txt"];
[self.dictionary setObject:self.textField.Text key:@"textField"];
[self.dictionary writeToFile:devicePath atomically:YES];
}
On your viewDidLoad, you can get the value of the file by:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"youefile"
ofType:@"txt"];
self.dictioary = [[[NSMutableDictionary alloc] initWithContentsOfFile:filePath] autorelease];