Reputation: 1063
There is nothing in the file, but I add row1 to my array right after. NSLog tells me that the array is empty. Why isn't row1 added to the array? All of my other code is fine as far as I can tell. My app worked when I put hard values into the array. Now that I'm loading from a file, it doesn't work.
- (void)viewDidLoad {
//array value
//NSMutableArray *array;
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
NSMutableArray *array/*array*/ = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
NSDictionary *row1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"Study", @"Task", @"2 hours", @"Length", @"4", @"Hours", @"0", @"Minutes", @"15", @"Tiredness", nil];
[array addObject: row1];
self.tasks = array;
NSLog(@"The contents of the array (file exists) is %@", array);
[array release];
[myTableView reloadData];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}
Please help!
Thanks in advance,
Matt
Upvotes: 0
Views: 238
Reputation: 34945
It is difficult to answer your question. Here are two suggestions:
When you post code here, clean it up. Remove comments and format it nicely.
Show all your code. In your code there could be many things wrong. Maybe the self.tasks property is not correct. Maybe you did not correctly setup the dataview. Maybe you did not implement the correct table view delegate methods. It is hard to tell.
Also, try ruling out the most basic things. For example if you are in doubt whether that array is setup correctly, then simply print it:
NSLog(@"The contents of the array is %@", array);
Upvotes: 0
Reputation: 237110
Two possibilities I see:
The object containing this code is not correctly set up as the table's datasource.
A file exists at the path you're looking at, but its contents cannot be parsed as an array. In this case, you would hit the first branch of the if-clause, but initWithContentsOfFile:
would return nil. You could easily diagnose this by checking for nil after calling that method.
Upvotes: 1
Reputation: 46985
make sure the tableview delegate and datasource is set properly
Upvotes: 0