I have a two column NSTableView that I want to populate with entries grabbed from a CSV file. Everything works fine except the title of each of the table cells isn't set.
Here's the function that is called for each row in the NSArray
- (void)populateTable:(NSString *)fname :(NSString *)lname {
NSMutableDictionary *value = [[NSMutableDictionary alloc] init];
[value setObject:[NSString stringWithFormat:@"%@", fname] forKey:@"first_name"];
[value setObject:[NSString stringWithFormat:@"%@", lname] forKey:@"last_name"];
[arrayController addObject:value];
[value release];
[fname_list reloadData];
[lname_list reloadData];
}
The value of the "last name" column is bound to the Array Controller arrangedObjects.last_name and both "first_name" and "last_name" are listed as keys in the Array Controller > Object Controller > Keys list
The proper amount of table cells are created (3 entries in the CSV file = 3 rows in each column), but the title of each of the cells isn't set (either to "first_name" or "last_name" depending on the column); the title of the cells just remains "Table View Cell"
Edit:
After using navinsillu's changes I end up with the following function:
- (void)populateTable:(id)sender :(NSString *)fname :(NSString *)lname {
[arrayController insert:sender];
[[[self arrayController] selection] setValue:fname forKeyPath:@"first_name"];
[[[self arrayController] selection] setValue:lname forKeyPath:@"last_name"];
[fname_list reloadData];
[lname_list reloadData];
}
And in my header I have
@property (retain,nonatomic,readwrite) IBOutlet NSArrayController *arrayController;
But I still get the same results: 3 rows/cells in each table column, all titled "Table View Cell"
Edit:
After some inspection I noticed that the Model Key Path
under the Value
bind for the table columns doesn't have any entries. When I type in first_name or last_name it says No completions found even though the keys are listed in the Keys
list in the array controller. Unfortunately I have no idea as to why it isn't finding the keys.
Edit:
Odd. I tried deleting and adding the table view and array controllers but that didn't work. However, creating a new project and doing the exact same things produces the expected results.
Recreating the project exactly the same way as I had it produces what I was expecting to happen. I'm not sure why redoing it all worked, but it did.