views:

51

answers:

2

Hi,

I've a mutable array that holds instances of a model object. That model object has several properties one being "name". I have no problems initialising or populating the mutable array.

I've a window with a drawer. I added a table to the drawer, the idea being that the drawer would use the table to display several instances of the model object.

I added an nsarraycontroller to the xib of the window that has a drawer. In the Array Controller Properties I've set the Object Controller to be an instance of the model class. On the Array Controller Bindings I set the Controller Content to point to the File Owner and set the Model Key Path to the name of the array.

On the table, I bind the content to the Array Controller, the Controller Key to arrangedObjects and Model Key Path to name.

My problem is that although the mutable array has been properly initialised and populated I can't see a single entry on the table on the drawer. Am I missing something here?

A: 

I assume you bound the tablecells table columns to the arraycontroller? I don't think Interface Builder will let you do anything else. Otherwise, it sounds like you have it configured properly.

I would recommend ibtool for troubleshooting these kinds of problems. It's a command line tool that does a text dump. You can inspect bindings in a more compact form than using the GUI in Interface Builder.

TechZen
You bind the table columns, not the cells.
Peter Hosey
Yes, I've been doing iPhone work recently.
TechZen
+1  A: 

Two possibilities:

First: you might have bound the wrong thing (your description here is a bit ambiguous). Bind each table column's "values" to the array controller's @"arrangedObjects.propertyName" (like arrangedObjects.firstName for the First Name column, etc.). There are alternative ways to bind the whole table, but you probably aren't binding the column's values, just the table's content.

Second: it's also possible the accessor to your model object isn't KVO compliant. Make sure proper KVO notifications wrap your setter accessor for your model array. If you've @synthesize'd it, all should be well. If you've hand-coded your accessors, all might not be well. :-)

Joshua Nozzi
Just having accessors isn't enough, either. You need to have accessors *and use them*. More details: http://boredzo.org/blog/archives/2008-11-26/how-to-work-with-a-bound-to-array
Peter Hosey
Yes - "don't modify the array behind the controller's back" is the current (and historic) Cocoa parlance. :-)
Joshua Nozzi
So which one was it, Rui? First or second? :-)
Joshua Nozzi
It was the second that solved my problem but I can't flag it as the chosen one, only vote for it as a good comment. On the other hand yours did help...
Rui Pacheco
:-) Decisions, decisions.
Joshua Nozzi