I have been bug searching the whole day and I found the problem but I don't know what is causing it. I have an IF statement that it skips since it can't find the property list. Upon entering a new viewController I have it read in the property list
I have one Method that creates the path to the file
Now in the next code I have the line if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) Looks like the IF statement is returning a FALSE since it is not running the code under it or printing the NSLog test that I set up. I have been cleaning up my code and moving things around so something go messed up, it was working fine last night. Does this code look right, or am I missing something?
Code:
- (void)viewWillAppear:(BOOL)animated
{
if (clientContentArray) { //test line to find problem
clientContentArray = nil;
}
[self readPlist];
[super viewWillAppear:animated];
}
I have one Method that creates the path to the file
Code:
- (NSString *) dataFilePath
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:@"clientList.plist"];
}
Now in the next code I have the line if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) Looks like the IF statement is returning a FALSE since it is not running the code under it or printing the NSLog test that I set up. I have been cleaning up my code and moving things around so something go messed up, it was working fine last night. Does this code look right, or am I missing something?
Code:
- (void)readPlist{
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSLog(@"I saw it");
clientContentArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
clientListForTable = [[NSMutableArray alloc] init];
client = [[NSMutableDictionary alloc]init];
if ([clientContentArray count] != 0) {
NSSortDescriptor *firstDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientNames" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
[clientContentArray sortUsingDescriptors:[NSArray arrayWithObject:firstDescriptor]];
for (int i = 0; i < clientContentArray.count; i++) {
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:[clientContentArray objectAtIndex:i]];
[clientListForTable addObject:[tempDict objectForKey:@"clientNames"]];
}
}
}
[self.tableView reloadData];
}