View Based Table - where is my data?

  • A NSTableView with one column which uses NSTableCellViews. Uses DataSource:

    - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
    {
    NSDictionary *aLine = self.dataArray[rowIndex];
    NSTableCellView *cellView = [ aTableView makeViewWithIdentifier: @"DieSpalte" owner: self ];
    [ cellView.textField setStringValue: aLine[kNameKey] ];
    [ cellView.imageView setImage: aLine[kImageKey] ];
    NSLog(@"%s %ld %@",__FUNCTION__, rowIndex, cellView);
    return cellView;
    }

    This method gets called as expected and returns non-nil NSTableCellViews.

    The Table has the right number of columns, but each column has the same picture (NSImageNameActionTemplate?) and the text of every row is: "Table View Cell".
    This is NOT what I want to see.
    How do I get the table to display my data?

    Gerriet.
  • On May 1, 2013, at 8:34 AM, Gerriet M. Denkmann wrote:

    > A NSTableView with one column which uses NSTableCellViews. Uses DataSource:
    >
    > - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

    This method does not get used at all.

    See the documentation:
    http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Tabl
    eView/PopulatingView-TablesProgrammatically/PopulatingView-TablesProgrammat
    ically.html


    --
    Seth Willits
  • On May 1, 2013, at 08:34 , "Gerriet M. Denkmann" <gerriet...> wrote:

    > - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
    > {
    > NSDictionary *aLine = self.dataArray[rowIndex];
    > NSTableCellView *cellView = [ aTableView makeViewWithIdentifier: @"DieSpalte" owner: self ];
    > [ cellView.textField setStringValue: aLine[kNameKey] ];
    > [ cellView.imageView setImage: aLine[kImageKey] ];
    > NSLog(@"%s %ld %@",__FUNCTION__, rowIndex, cellView);
    > return cellView;
    > }

    This is wrong. You should not create a cell view in this method, and you should not return a cell view as a result. The value returned from this method becomes the the "objectValue"  property of the cell view. Because you're trying to create the cell view in the wrong place, the table view is creating one for you (a different one), and that view isn't getting its text or image set to anything useful.

    Instead, you should be putting the above code in a 'tableView:viewForTableColumn:row:' delegate method. Since you're (apparently) not using any bindings within your cell view, you don't need objectValue at all -- neither the data source method nor the property.
  • On 1 May 2013, at 23:51, Quincey Morris <quinceymorris...> wrote:

    > On May 1, 2013, at 08:34 , "Gerriet M. Denkmann" <gerriet...> wrote:
    >
    >> - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
    >> {
    >> NSDictionary *aLine = self.dataArray[rowIndex];
    >> NSTableCellView *cellView = [ aTableView makeViewWithIdentifier: @"DieSpalte" owner: self ];
    >> [ cellView.textField setStringValue: aLine[kNameKey] ];
    >> [ cellView.imageView setImage: aLine[kImageKey] ];
    >> NSLog(@"%s %ld %@",__FUNCTION__, rowIndex, cellView);
    >> return cellView;
    >> }
    >
    > This is wrong. You should not create a cell view in this method, and you should not return a cell view as a result. The value returned from this method becomes the the "objectValue"  property of the cell view. Because you're trying to create the cell view in the wrong place, the table view is creating one for you (a different one), and that view isn't getting its text or image set to anything useful.
    >
    > Instead, you should be putting the above code in a 'tableView:viewForTableColumn:row:' delegate method. Since you're (apparently) not using any bindings within your cell view, you don't need objectValue at all -- neither the data source method nor the property.

    You are absolutely right.
    And I was confused, because before I implemented my data-source method numberOfRowsInTableView: I was told: " *** Illegal NSTableView data source (<TbViAppDelegate: 0x101a22760>).  Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:" which seems not really true after all.

    Thanks a lot!

    Kind regards,

    Gerriet.
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today