On Jan 26, 2009, at 7:00 PM, kentoz...@comcast.net wrote:
> See:
> -[NSTableView tableView:dataCellForTableColumn:row:]
I took a look at that but it really seems to complicate things.
... sorry?
How does implementing one delegate method that's directly targeted
at the very problem you're trying to solve "complicate things"?
Basically, I create the table and bind it to it's data source
programatically. Once the table is bound and added to a view, the
row count is known, so all I need to do is set that one cell.
Yes, which is precisely what the above-referenced delegate method
is intended to do. Whether your table uses bindings or a data source
is completely irrelevant. You want to manipulate or swap cells for a
given column on a per-row basis? This is *the* method intended for
that purpose.
I got part way there by doing:
...
Which works, only problem is, it changes the image and target for
every cell in the column.
Well what did you expect it to do?
Again ... you don't get a reference to an individual cell at a row/
column. Tables don't work that way in Cocoa. The cell for a column is
a *prototype* cell that's reused (changed and re-rendered in the
proper position per row). Changing the data cell changes the *one*
prototype that's used.
Have you bothered to read the table programming guide I referenced?
It explains all this.
Is there no other way to do this other than ditching my table
creation code completely and using a delegate?
Why would you have to "ditch" your table creation code? All you
have to do is set the table's delegate if you haven't already, then
answer the delegate method with the preferred cell. You can even
ignore columns you're not interested in messing with.
As above two lines indicate, this kind of thing should be trivial to
do directly, provided there is some way to set the data cell.
Indicate? The above two lines *WILL NOT WORK*, so all they indicate
is that you didn't read the documentation or follow the advice you
asked for.
You're right, though, it *is* trivial and there *is* a way to set
the data cell: exactly the way I pointed you to. It just doesn't work
the way you expect it to (and for good reason - if there were
literally a cell object for each 'box' in the table view, tables would
be slow-moving memory hogs.
I just don't get why you're trying so hard to fight the frameworks
when all you have to do is implement one method and create/maintain a
single cell. This *is* the way it's done and it works quite well and
will take you all of five minutes to implement.
It doesn't matter how you created your table (in code or not) as
it's a delegate method. It doesn't matter whether you're bound or use
the <NSTableDataSource> protocol ... because again, this is a delegate
method. This weird phobia people seem to have with mixing data source
and bindings seems to stretch to using delegate methods too, which is
even more absurd ...
--
I.S.
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com