Re: Cell alignment within a NSTableColumn
Re: Cell alignment within a NSTableColumn
- Subject: Re: Cell alignment within a NSTableColumn
- From: Nicholas Riley <email@hidden>
- Date: Tue, 22 Oct 2002 16:07:20 -0500
- Mail-followup-to: Stéphane Sudre <email@hidden>, email@hidden
On Tue, Oct 22, 2002 at 12:54:37PM +0200, Stiphane Sudre wrote:
>
How do you get the data cell alignment within a NSTableColumn?
>
>
I'm pretty sure the answer is obvious but I don't find it. [NSCell
>
alignment] is always returning me 0 (Left Alignment).
>
>
I have a custom NSCell as the dataCell for the NSTableColumn. I tried
>
both with subclassing NSCell and NSActionCell. Same results.
The more important question is "how, and when, do you set the data
cell alignment?" Are you doing it from IB, or from code?
Your problem here, most likely, is that you're setting the alignment
in the NSTableColumn inspector in Interface Builder, and are creating
your cell programmatically after Interface Builder has set the
alignment for you. It seems the intended pattern is that you hook up
the dataCell outlet of the NSTableColumn in IB to an instance of your
cell subclass. But, at least in IB 2.2.1 you can't instantiate NSCell
subclasses in IB directly.
If you're doing what my code did, there's a line in awakeFromNib or
similar which instantiates the cell and invokes -[NSTableColumn
setDataCell:]. awakeFromNib is called after Interface Builder has
unarchived its objects, and set the cell properties on the default
NSTextFieldCell, which you proceed to replace with your own cell, so
all the settings are ignored.
The quickest thing to do is simply insert a call to -[NSCell
setAlignment:] immediately after you instantiate the cell. There is a
workaround if you want to do it all in IB:
- Drag a NSTextField from the palette onto your window.
- Option-drag a handle of the text field to create a 2x1 or 1x2 NSMatrix.
- Set the matrix size back to 1x1.
- Double-click the matrix: you now can target the NSCell in the
inspector. Set the cell's class to your custom class.
- Set the attributes of the cell if appropriate: set the border to
transparent, turn off "Draws Background", etc. otherwise the table
cell will look weird.
- Connect the dataCell outlet of the table column to the interior of the
matrix: you'll target an instance of your NSCell subclass.
- Give the cell negative coordinates so it isn't visible. You can
still access it from the outline view in the Instances tab.
Notice that you can set the alignment of your NSCell subclass's
instance, _or_ of the NSTableColumn, but it appears that the
NSTableColumn's setting takes precedence.
This is all assuming there's something I'm missing about being able to
hook up dataCell... I did a reasonable amount of searching and was not
able to find any documentation or discussion of this point.
--
=Nicholas Riley <email@hidden> | <
http://www.uiuc.edu/ph/www/njriley>
Pablo Research Group, Department of Computer Science and
Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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.