views:

196

answers:

1

I want to auto resize table column to its content width when double clicking its header (resize cursor is showing), like on iTunes.

Anyone know how to do it ?

Thanks in advance

+1  A: 

Look at the NSTableView method setDoubleAction:. You can probably set it up from Interface Builder, too - I didn't check. From the documentation:

setDoubleAction:

Sets the message sent to the target when the user double-clicks an uneditable cell or a column header to a given selector.

- (void)setDoubleAction:(SEL)aSelector

Parameters
aSelector
The message the receiver sends to its target when the user double-clicks an uneditable cell or a column header.

Discussion
If the double-clicked cell is editable, this message isn’t sent and the cell is edited instead. You can use this method to implement features such as sorting records according to the column that was double-clicked. See also clickedRow which you can use to determine if a row was clicked rather than the column heading.

For the method to have any effect, the receiver’s action and target must be set to the class in which the selector is declared. See Action Messages for additional information on action messages.

Carl Norum
It's executed when double clicking header but not when resize cursor is showing.
Irwan