In article <DISdnee9BawuBczVnZ2dnUVZ_j6dnZ2d@[EMAIL PROTECTED]
>,
Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> In article <uce-A0C594.15245212062008@[EMAIL PROTECTED]
>,
> Gregory Weston <uce@[EMAIL PROTECTED]
> wrote:
>
> > In article <2oydneAWac0i9czVnZ2dnUVZ_qLinZ2d@[EMAIL PROTECTED]
>,
> > Don Bruder <dakidd@[EMAIL PROTECTED]
> wrote:
> >
> > > The CocoaDev site that Reinder pointed me at was *VERY* useful - At
> > > least now I think I've got the beginnings of a grip on how to use
> > > NSTableView.
> > >
> > > Except for one minor detail...
> > >
> > > ...
> > >
> > > // This routine appears to never get called.
> > > // Putting a breakpoint (or several of them) anywhere in it does
nothing
> > > whatsoever. I strongly suspect that this is the reason I'm getting a
> > > blank NSTableView displayed, but I don't know where to look for the
> > > problem. If it were to execute, it looks like it *SHOULD* do what
it's
> > > supposed to. But it doesn't seem to get executed, and I don't know
why.
> > > - (id)tableView:(NSTableView *)aTable
> > > objectValueForColumn:(NSTableColumn *)aCol row:(int)aRow
> > > {
> > > id loc_id, loc_dat;
> > > NSMutableArray *loc_col;
> > >
> > > loc_id = [aCol identifier];
> > > if (loc_id != nil)
> > > {
> > > loc_col = [itemList objectForKey:loc_id];
> > > if (loc_col != nil)
> > > {
> > > loc_dat = [loc_col objectAtIndex:aRow];
> > > }
> > > }
> > > return (loc_dat);
> > > }
> >
> > The first thing I want to say is this:
> >
> > A dictionary of arrays is going to be a lot harder to sort than an
array
> > of dictionaries when/if you decide that's something you want to do.
>
> Keep in mind that I've pretty much lifted everything involved from
> CocoaDev's example, which is, no doubt, anything but optimal for what
> I'm doing...
>
> The way I've got things built now, a single swap during the sort is
> actually going to involve seven swaps. I can see that already. So
> slower/more tedious? Definitely. Harder? I can't see why. A generic
> "Here's an array and two indices - swap the items at the indices"
> routine won't be that difficult to do.
Swapping two arbitrary items will be harder (not hard, just hardER) to
write and maintain because the amount of code will be multiplied by the
number of arrays and will have to be updated every time an array is
added or removed.
Doing a full arbitrary sort will be a complete bugger. You'll have to
write your own sort routine that takes (or knows about) a collection of
parallel arrays and is informed which array(s) are to be used as sort
keys, and then do the compare/swap dance manually.
For an array of dictionaries, no matter how many columns in your table,
sorting on an arbitrary subset of columns will take roughly 3 lines of
code. And can trivially be rigged to be triggered by the NSTableView
itself when the user clicks on column headings.
> > The second thing - and the actual answer to your problem - is that
> > you've named the method incorrectly. I'd be marginally surprised if
> > you're not getting a message emitted when you run that says the object
> > isn't responding correctly.
>
> Nope... No compile/link messages, no runtime messages, no nothing - Just
> silently failing to perform as expected.
>
> Of course, now that I think about it a bit, it's not particularly
> surprising that nothing shows up - the NSTableView code is looking for a
> routine with the right name.
That's what I find surprising, though. NSTableView is looking for a
routine with the right name and not finding one. I find it strange that
you're not getting a message to the console at runtime alerting you to
that. It wouldn't complain that "you named the method wrong" because it
doesn't know that you tried to provide the method. It would complain
that "you didn't implement a method that the datasource is required to
provide."
I'm on a machine with 10.4.11 right now, and I've just created a new
Cocoa project, thrown a table on the window and linked it to an NSObject
subclass that has no new methods.
On launch I get this:
"*** Illegal NSTableView data source (<untitled: 0x358640>). Must
implement numberOfRowsInTableView: and
tableView:objectValueForTableColumn:row:"
Interesting, though. I added this:
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return 7;
}
And now get no message at all. I've confirmed your results and I think
I'll be filing a bug re****t over it if it behaves the same way on 10.5.
If I remove that method and add tableView:objectValueForTableColumn:row:
I get the warning again.
> That entire routine is lifted almost verbatim (except for my changing
> the variable name they used from I-forget-what-it-was to "itemList" to
> match what I already had going on in the project) from the CocoaDev
> site. Either they've got a buggy example up, the API has changed since
> they posted it, or I somehow managed to mangle it during the copy/paste.
Looks like door #3. That API hasn't changed and today the code on
CocoaDev looks right. Unless I looked at a different page of theirs than
you used.
> Thanks yet again!
No problem.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
- Harry Potter and the Odor of the Phoenix


|