Table column index
-
Is it safe to assume that the column indexes returned by various
NSTableView routines are in fact indexes into [NSTableView
tableColumns]? I can't find anything in the documentation that says
this. -
Those methods return NSInteger's. To get a reference to the
NSTableColumn you should call something like
int column = [[yourTableView selectedColumn] intValue];
NSTableColumn myColumn = [[yourTableView tableColumns] objectAtIndex:column];
Adam
On Mon, Feb 25, 2008 at 3:46 PM, Quincey Morris
<quinceymorris...> wrote:
> Is it safe to assume that the column indexes returned by various
> NSTableView routines are in fact indexes into [NSTableView
> tableColumns]? I can't find anything in the documentation that says
> this.
>
-
On Feb 25, 2008, at 14:06, Adam Gerson wrote:
> Those methods return NSInteger's. To get a reference to the
> NSTableColumn you should call something like
>
> int column = [[yourTableView selectedColumn] intValue];
> NSTableColumn myColumn = [[yourTableView tableColumns]
> objectAtIndex:column];
It looks you're suggesting I send an intValue message to a NSInteger.
That wouldn't work. :)
What I was asking about is whether (for example, and assuming a column
is selected)
[[tableView tableColumns] objectAtIndex: [tableView selectedColumn]]
is in fact the NSTableColumn that's selected. It seems likely, but the
documentation does not say, that the order of the NSTableColumns in
[NSTableView tableColumns] is the same as the current visible order of
the columns in the table. -
On Feb 25, 2008, at 4:41 PM, Quincey Morris wrote:
> What I was asking about is whether (for example, and assuming a
> column is selected)
>
> [[tableView tableColumns] objectAtIndex: [tableView selectedColumn]]
>
> is in fact the NSTableColumn that's selected. It seems likely, but
> the documentation does not say, that the order of the NSTableColumns
> in [NSTableView tableColumns] is the same as the current visible
> order of the columns in the table.
And it actually hints to the contrary, since -tableColumns is document
to include the hidden columns as well (and doesn't say if they are at
the end or in the middle)
However, as long as you only refer to your table columns by their
identifiers, you can ignore it one way or the other. For example, if
you want to know if the column whose identifier is "Name" is the
selected column, you can do something like:
if ([[table isColumnSelected: [table columnWithIdentifier: @"Name"]]) {
// the column "Name" is selected
}
By adapting the practice of using the column identifier, not only do
you get past this problem, you won't have any problem if you allow the
user to re-order columns.
Glenn Andreas <gandreas...>
<http://www.gandreas.com/> wicked fun!
quadrium | prime : build, mutate, evolve, animate : the next
generation of fractal art -
On Feb 25, 2008, at 15:12, glenn andreas wrote:
> And it actually hints to the contrary, since -tableColumns is
> document to include the hidden columns as well (and doesn't say if
> they are at the end or in the middle)
I just tried it, and the column numbers seem to match up with the
array indexes even when a column is hidden.
> By adapting the practice of using the column identifier, not only do
> you get past this problem, you won't have any problem if you allow
> the user to re-order columns.
I would if I could, but I'm subclassing NSTableColumn and I can't
really assume that an instance either has an identifier, or has a
unique identifier, and either of those cases will make
columnWithIdentifier unreliable. (I'm trying to have the column get
its index so that it can call rectForColumn.) -
On Feb 25, 2008, at 4:41 PM, Quincey Morris wrote:
>
> On Feb 25, 2008, at 15:12, glenn andreas wrote:
>
>> And it actually hints to the contrary, since -tableColumns is
>> document to include the hidden columns as well (and doesn't say if
>> they are at the end or in the middle)
>
> I just tried it, and the column numbers seem to match up with the
> array indexes even when a column is hidden.
Yes, as you discovered, there is always a 1-to-1 correspondence for
the column index into the array. Anything else would be too difficult
to work with (you'd always have to subtract hidden column indexes that
appeared before a given index).
Since this wasn't clear, can you please log a documentation bug
requesting clarification? You can copy-paste this email as reference
(and describe your initial question) and refer the documentation team
to me.
-corbin



