Re: NSFormatter and the nib
Re: NSFormatter and the nib
- Subject: Re: NSFormatter and the nib
- From: Andy Lee <email@hidden>
- Date: Mon, 24 Jun 2002 10:31:36 -0400
Hi, Jim.
At 8:16 AM -0500 6/24/02, Jim Menard wrote:
In IB, I can drag an NSDateFormatter or NSNumberFormatter onto the instance
window. I can't seem to do anything with it, either in IB or in my
application. How do I "retrieve" one of these from the nib when my
application is running?
It looks like there is a slightly better approach, but first (because
I like to hear myself talk) I'll answer this question. if
(youJustWantTheShortAnswer) goto SHORT_ANSWER;
You need something in your nib file to have an outlet to the
formatter instance. If the nib is MainMenu.nib, maybe you have some
sort of controller or delegate object in there that you've defined.
If the nib is a separate nib, it's likely the File's Owner of the nib
is a class of yours. Either way, add an ivar to your object, inform
IB about the ivar, and connect your object to the formatter instance
via Control-drag in IB. Then your object can obviously refer to the
formatter in whatever code you want.
It's the same as for accessing any object you add to the instance window.
(In NextStep there used to be a way to name things in a nib and ask
for them by name, but I think that's gone.)
I know how to programatically create formatters and "give" them to my
NSTableView's column's data cells. I just don't know how to use something
stored within a nib file.
*If* you take the above approach of creating the formatter instance
in the instance window, you can specify the table column's
"dataCell", and you can specify that cell's "formatter", as follows:
(1) Drop a text field into your nib.
(2) Use Option-drag to make the text field into a multi-cell matrix.
If you only need one formatter cell, Option-drag it back to a 1x1
matrix. (It seems to have to be an NSMatrix for you to make IB
connections to the cell.)
(3) Select the *cell* in IB by double-clicking the 1x1 matrix.
Control-drag from the cell to the formatter instance in your instance
window. Set the cell's "formatter" outlet to be the formatter.
(4) Select the column of the NSTableView you care about. Do this by
double-clicking a couple of times. (The Inspector window should say
"NSTableColumn Info" in its title.)
(5) Control-drag from the column header to the cell you created. Set
the column's "dataCell" outlet to the cell.
(6) Don't blame me if this doesn't do what you want, because I
haven't actually tried it.
SHORT_ANSWER:
There seems to be a simpler way altogether: I can drag a formatter
instance from the palette right onto the table column. Is this not
true for you? I am using the April 2002 Dev Tools, so maybe that
matters. Anyway, once you've done that, you can select the table
column (just the column within the table, not the whole table) and
tweak its formatter in the Inspector window. When you add a
formatter to something, the Inspector window acquires a "Formatter"
pane that you can get to via the popup menu or by hitting Command-7.
I haven't tested this in action; I'm just tellin' you what I saw when
I putzed around.
--Andy
_______________________________________________
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.