RE: Fun with table column identifiers
RE: Fun with table column identifiers
- Subject: RE: Fun with table column identifiers
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 28 Oct 2002 15:24:44 -0500
>
I am working on an app that requires that the number of table columns in a
>
table view be determined at run time.
>
>
My first solution was to create the table view with no columns
>
and then add
>
the columns at the appropriate time.
>
>
The problem with this approach is that the column headers lose their Aqua
>
look.
>
>
My next approach was to create a table view with one column in IB. I then
>
did a deep copy of the one column, this kept the Aqua look of the header.
>
Another approach you might consider is creating all of the columns you might
ever possibly need in IB (with appropriate formatters). In awakeFromNib,
you can add all the tablecolumns to a dictionary (using the identifiers as
keys). Then remove the ones you don't need from the tableview. If you need
to later put a column back in the tableview, just retrieve it from the
dictionary.
>
One nagging irritation, in IB if I enter a 1 (that9s a one with no quotes)
>
for the column identifier, I do not seem to be able to retrieve the column
>
from the table view via the call
>
>
tmp = [tableView tableColumnWithIdentifier:
>
[NSNumber numberWithInt:1]];
I think the reason this won't work is that the identifier is an NSString
when it is set in IB, not an NSNumber.
>
Or
>
tmp = [tableView tableColumnWithIdentifier:
>
@212];
I assume that those twos are quotes and outlook is playing a joke on me.
I think this ought to work. Have you verified that IB actually set the
identifier? I have found that some of the palettes are very stubborn and
refuse to take values the first time you type them. My workaround has been
to type, tab, then (if necessary) shift-tab and reenter. Repeat as needed.
>
I also tried several variation the the NSNumber construction, but
>
never was
>
able to get the column!
>
>
It is important that I index the columns with NSNumber objects.
You could set the identifiers with numerals in IB. Then enumerate through
[tableView tableColumns] and use setIdentifier: to change each identifier
into its NSNumber equivalent.
>
..So the
>
question is:
>
>
If you type an integer in for the column identifier, how can you
>
retrieve the column?
I think the short answer is that thing you are typing in IB is not an
integer. That numeral is treated as an NSString. If you want an identifier
that isn't an NSString, I think you need to programmatically set the
identifier, as you do here:
>
>
My (temporary I hope) workaround is to create the single column with
>
identifier foo, then in my awakeFromNib routine I do:
>
>
[ [tableView tableColumnWithIdentifier:@"foo"] setIdentifier:[NSNumber
>
numberWithInt: 0]];
>
>
This seems like an inelegant solution to the problem.
You want elegant? Go to the ballet.
Perhaps a more elegant solutions is possible if you reexamine the
requirement that your identifiers be NSNumbers.
Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.