0

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.

  • 1
    show the code where you creating the cell. – Manish Agrawal Oct 23 '12 at 04:06
  • That is the code up above. The array controller bound to the columns of the NSTableView is told to add an object with identifier keys. It does that just fine but instead of getting a Last Name column with results like "Smith", "Johnson", and "Stevenson" I get "Table View Cell", "Table View Cell", and "Table View Cell". –  Oct 23 '12 at 04:12
  • this code will only set the array, I want this method code - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath – Manish Agrawal Oct 23 '12 at 04:18
  • I don't have anything for that. The array controller adds the data in populateTable and the table view is reloaded with the data from the array controller –  Oct 23 '12 at 04:22
  • Is this a view based or cell based table? – rdelmar Oct 23 '12 at 19:17

2 Answers2

0

You can set your title at the table header in Interface Builder.you can double click the table column header and set title for it.Like this we can set header t o table column

NewStack
  • 990
  • 8
  • 19
  • Oh no, I have that set and everything. What I'm doing is loading a CSV file when the application launches and for each row in the CSV file it will create a cell in a table column. It's supposed to set the title of the cell (Default is "Table View Cell") to the corresponding data from the CSV file but it doesn't. When I do an NSLog of the object `value` it shows the correct data, but the title of each of the table cells isn't changed. I can't use images here yet but this is what I mean: http://i.imgur.com/4VFrq.png –  Oct 23 '12 at 04:48
  • ok you can use `@property (retain,nonatomic,readwrite) IBOutlet NSArrayController *arraycontroller;` then `[[[self arraycontroller] selection] setValue:fname forKeyPath:@"frist_name"];` [`[[self arraycontroller] selection] setValue:lnameforKeyPath:@"last_name"];` – NewStack Oct 24 '12 at 04:23
  • I just tried applying your changes, but I still get the same result –  Oct 24 '12 at 05:11
0

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.