View Based TableView - how to use bindings?

  • I have a view-based table view which currently uses a DataSource.
    But I would like to use bindings instead.
    I know how to do this with a cell-based table view - and I was following "Populating View-Based Table Views using Cocoa Bindings".

    My array controller has arrangedObjects which seem to be right.
    But my table is absolutely empty.

    The Array Controller has it's content bound to some array of dictionaries, which have the keys "Name" and "Image".
    The table view's content is bound to Array Controller arrangedObjects. The only TableColumn is not bound to anything.
    The Image View of the Table Cell View has it's Value bound to Table Cell View objectValue.Image.
    The Static Text of the Table Cell View has it's Value bound to Table Cell View objectValue.Name.

    But still - the table remains empty.

    What might I be missing?

    Gerriet.
  • On May 1, 2013, at 11:52 , "Gerriet M. Denkmann" <gerriet...> wrote:

    > The Array Controller has it's content bound to some array of dictionaries, which have the keys "Name" and "Image".
    > The table view's content is bound to Array Controller arrangedObjects. The only TableColumn is not bound to anything.
    > The Image View of the Table Cell View has it's Value bound to Table Cell View objectValue.Image.
    > The Static Text of the Table Cell View has it's Value bound to Table Cell View objectValue.Name.
    >
    > But still - the table remains empty.

    What kind of empty? Are there any rows? Can you select rows by clicking on them, even if their content is blank?

    Are you sure there aren't any exception or other messages in the Console log that you didn't see?

    You could try temporarily unbinding the image and text properties of the cell view, so that they should display whatever they're showing in IB. That might give a clearer idea of whether it's the binding from the table to the array controller that's at fault, or the bindings from the cell subviews to the cell view.

    Do you still have a 'tableView:objectValue…' method, or do you set objectValue in 'tableView:viewWithIdentifier…'? Neither should be necessary when using the table view binding to the array controller.

    Is your cell view a subclass of NSTableCellView, or something else? Are you trying to use the built-in (design-time) table cell view, or have you registered a nib to provide the cell views?

    Are you sure you're using the correct view identifier in 'tableView:viewWithIdentifier…'? Are you sure 'makeViewWithIdentifer:' isn't returning nil?

    Are you sure this is a table view issue, and not a KVO compliance issue with the property that's supplying the array controller content?

    There's lots that can go wrong here. :)
  • On 2 May 2013, at 02:16, Quincey Morris <quinceymorris...> wrote:

    > On May 1, 2013, at 11:52 , "Gerriet M. Denkmann" <gerriet...> wrote:
    >
    >> The Array Controller has it's content bound to some array of dictionaries, which have the keys "Name" and "Image".
    >> The table view's content is bound to Array Controller arrangedObjects. The only TableColumn is not bound to anything.
    >> The Image View of the Table Cell View has it's Value bound to Table Cell View objectValue.Image.
    >> The Static Text of the Table Cell View has it's Value bound to Table Cell View objectValue.Name.
    >>
    >> But still - the table remains empty.
    >
    > What kind of empty?
    Completely.
    > Are there any rows?
    Can't see any.
    > Can you select rows by clicking on them, even if their content is blank?
    No, there really seem to be no rows at all.
    >
    > Are you sure there aren't any exception or other messages in the Console log that you didn't see?
    No exceptions in Xcode - none in Console.app.
    >
    > You could try temporarily unbinding the image and text properties of the cell view, so that they should display whatever they're showing in IB. That might give a clearer idea of whether it's the binding from the table to the array controller that's at fault, or the bindings from the cell subviews to the cell view.
    Did unbind both image and name. Still no rows.
    >
    > Do you still have a 'tableView:objectValue…' method, or do you set objectValue in 'tableView:viewWithIdentifier…'? Neither should be necessary when using the table view binding to the array controller.
    I had "-tableView: viewForTableColumn: row:" - have just removed it. Still no rows.

    >
    > Is your cell view a subclass of NSTableCellView, or something else? Are you trying to use the built-in (design-time) table cell view, or have you registered a nib to provide the cell views?
    Just a plain NSTableCellView.
    >
    >
    > Are you sure you're using the correct view identifier in 'tableView:viewWithIdentifier…'? Are you sure 'makeViewWithIdentifer:' isn't returning nil?
    Can't find the method: 'tableView:viewWithIdentifier…'. But makeViewWithIdentifier:... is never called. It was used in ...viewForTableColumn:... which was never called and has just been removed.
    I guess this is the root of the problem: I do not know where to call makeViewWithIdentifier.
    But do I need to? both things in the NSTableCellView have bindings already.

    >
    > Are you sure this is a table view issue, and not a KVO compliance issue with the property that's supplying the array controller content?
    id g = [ self.arrayController arrangedObjects ]; // _NSControllerArrayProxy
    NSLog(@"%s arrangedObjects %ld ",__FUNCTION__, [g count]);
    prints 39 as expected. So the array controller is not empty. It also contains correct objects.

    Just bound the image to "objectValue.AbsoluteNonsense" and did not get any error messages. Is this normal?

    Well - will try more tomorrow. It is almost three in the morning an I am tired.

    Thanks for your help!

    Kind regards,

    Gerriet.
  • On May 1, 2013, at 12:52 , "Gerriet M. Denkmann" <gerriet...> wrote:

    > Can't find the method: 'tableView:viewWithIdentifier…'. But makeViewWithIdentifier:... is never called. It was used in ...viewForTableColumn:... which was never called and has just been removed.
    > I guess this is the root of the problem: I do not know where to call makeViewWithIdentifier.
    > But do I need to? both things in the NSTableCellView have bindings already.

    The header comments for 'tableView:viewForTableColumn:' say:

    > Bindings: This method is optional if at least one identifier has been associated with the TableView at design time. If this method is not implemented, the table will automatically call -[self makeViewWithIdentifier:[tableColumn identifier] owner:[tableView delegate]] to attempt to reuse a previous view, or automatically unarchive an associated prototype view.

    So you don't need the method (because you have bindings), but you need to make sure that the table column identifier matches the interface identifier of the "prototype" view.

    > id g = [ self.arrayController arrangedObjects ];    //    _NSControllerArrayProxy
    > NSLog(@"%s arrangedObjects %ld ",__FUNCTION__, [g count]);
    > prints 39 as expected. So the array controller is not empty. It also contains correct objects.
    >
    > Just bound the image to "objectValue.AbsoluteNonsense" and did not get any error messages. Is this normal?

    If it's not creating any cell views, there won't be any errors.

    I think you still need to find out whether it's the table view binding or the cell view binding that's failing. You could insert a line of code, after the table view is supposedly initialized, to query the number of rows and see if it's 39.

    Note that the fact that the array controller contains the right objects doesn't necessarily mean anything, if KVO compliance is messed up. It's a matter of timing, in that case, as to what results you get. You could try throwing in a 'reloadData' for the table, once you're sure the array controller has the right content, and see if that changes things. If so, you have a KVO compliance problem earlier in the initialization.
  • On 2 May 2013, at 03:16, Quincey Morris <quinceymorris...> wrote:

    I got it working.
    Formerly I had:
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    self.dataArray = [ NSMutableArray array ]; // this is the content of my ArrayController
    for(...) { fill self.dataArray with 39 Dictionaries };
    }

    I changed this to:
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    NSMutableArray *tempArray = [ NSMutableArray array ];
    for(...) { fill tempArray with 39 Dictionaries };
    self.dataArray = tempArray;
    }

    And now it works.
    In the bad old style the ArrayController knew it had 39 objects, but the TableView still thought there were 0.
    Now everything is in sync.

    >> Just bound the image to "objectValue.AbsoluteNonsense" and did not get any error messages. Is this normal?
    >
    > If it's not creating any cell views, there won't be any errors.
    Now that cell view ARE created, there are still no errors. There just are no images in my table.

    Anyway - thanks a LOT for your help!

    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