NSTableView behaviour question

Discussion in 'Mac Programming' started by gekko513, Apr 28, 2006.

  1. macrumors 603


    Oct 16, 2003
    I find it difficult to control some of the behaviour of an NSTableView in Cocoa. Maybe I'm just missing something.

    I want to change three things:
    1. To disable user selectable sorting on the columns.
    2. To disable column AND row selection in the table view. I don't want the user to be able to select anything.
    3. To disable editing of the text in all cells.

    Can I do this? How?
  2. Moderator emeritus


    Jul 24, 2002
    I think you can set all of these attributes in Interface Builder. Unfortunatly I'm not on a Mac now so I can't post a screenshot of the boxes you want...

    [​IMG] You can column sizing and reordering here. You need to turn off cell editability on a per column basis I think.
  3. macrumors 603


    Aug 2, 2002
    Cork, Ireland.
    Not certain, if you disable "Column Selection" does that do it? Otherwise, perhaps implementing tableView:shouldSelectTableColumn: in the NSTableView's delegate object, and returning NO might do it.

    One way, is to implement 'selectionShouldChangeInTableView:' in the delegate object, and return NO.

    Select each column in turn (by repetitively double clicking them), then open the inspector and uncheck "Editable".
  4. thread starter macrumors 603


    Oct 16, 2003
    I did it!

    1. The solution wasn't very intuitive. I found it here:
    Disabling sorting in a tableview

    (Courtesy of James Dempsey.)

    To disable sorting in a tableview you need to do the following:

    - Select the table view itself and inspect its bindings.

    - You will see three Table Content bindings for the table view:
    • content
    • selectionIndexes
    • sortDescriptors
    - Bind the content to:
    • Bind To: Your Array Controller
    • Controller Key: arrangedObjects
    • Model Key Path: <leave this blank>
    Bind selectionIndexes to:
    • Bind To: Your Array Controller
    • Controller Key: selectionIndexes
    • Model Key Path: <leave this blank>
    - Leave sortDescriptors unbound

    2. Thanks whooleytoo, the - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex delegate method did it. I was trying to make a value transformer for the selectionIndexes bindings to zero out the selection. That worked in a non-desirable way. The row did go selected (blue) on mouse down and was unselected on mouse up.

    3. The column header "editable" attribute did the trick. Thanks to both of you.

Share This Page