I tried to modify it a bit and looked at other options here and googled some stuff but nothing seems to work.
here's what I have, like I said, It works perfectly in the simulator but not the device, witch runs iOS 5.x I thanks for all the help.
NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;
filemgr = [NSFileManager defaultManager];
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
//Build the path to the data file
datafilePath = [[NSString alloc] initWithString: [docsDir
stringByAppendingPathComponent: @"data.archive"]];
// NSString *localPath = @"Documents/data.archive";
// datafilePath = [NSHomeDirectory() stringByAppendingPathComponent:localPath];
// Check if the file already exists
if ([filemgr fileExistsAtPath: datafilePath])
{
NSMutableArray *dataArray;
// NSDictionary *stuff;
dataArray = [NSKeyedUnarchiver
unarchiveObjectWithFile: datafilePath];
for(int i=0; i< [dataArray count]; i++){
titlestring = [dataArray objectAtIndex:i ];
detailsstring = [dataArray objectAtIndex:++i];
// date = [dataArray objectAtIndex:2];
[tabledata addObject:titlestring];
[tablesubtitles addObject:detailsstring];
}
}
}
this is the saveButton action: Like I said, I works fine in the simulator, just doesn't do anything in the device, everything shows up blank.
if (i == 0) {
// [userDefaults setObject:titlefield.text forKey: @"titlehomework"];
// [userDefaults setObject:detailstextfield.text forKey:@"detailshomework"];
NSMutableArray *contactArray;
contactArray = [NSKeyedUnarchiver
unarchiveObjectWithFile: datafilePath];
// contactArray = [[NSMutableArray alloc] init];
[contactArray addObject:titlefield.text];
[contactArray addObject:detailstextfield.text];
[NSKeyedArchiver archiveRootObject:
contactArray toFile:datafilePath];
// NSDictionary *stuff;
}