Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gekko513

macrumors 603
Original poster
Oct 16, 2003
6,301
1
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?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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...

LCoc_1014.gif
You can column sizing and reordering here. You need to turn off cell editability on a per column basis I think.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
gekko513 said:
I want to change three things:
1. To disable user selectable sorting on the columns.

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.

gekko513 said:
2. To disable column AND row selection in the table view. I don't want the user to be able to select anything.

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

gekko513 said:
3. To disable editing of the text in all cells.

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

gekko513

macrumors 603
Original poster
Oct 16, 2003
6,301
1
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.