Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't make NSTableView editable via click

I'm trying to make a simple NSTableView (text only) where the cell views can be clicked upon to edit the text. All the tutorials and related questions here suggest that this is the automatic behaviour, but I can't get it.

I have no trouble linking my delegate and data-sources; I can populate all the cells programmatically, and I can figure out what to do with the new text that is entered upon editing. ... I just can't get the text box to open for editing!

(The NSTable columns are marked as editable in IB)

Thanks for any clues.

like image 423
Joey FourSheds Avatar asked Feb 02 '13 18:02

Joey FourSheds


1 Answers

You can do this in Interface Builder by selecting the Text Field Cell, then using the Attributes Inspector, scroll down to the drop down menu entitled "Behavior" and choose "Editable".

This alone will enable you to be able to double-click on individual cells and have them become an editable TextField.

To make the edits you make have an effect, you will also have to implement the following method from the NSTableViewDelegate Protocol: - (void)tableView:setObjectValue:forTableColumn:row:

[See Apple Docs for this function] (https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTableDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSTableViewDataSource/tableView:objectValueForTableColumn:row:)

As usual, this method will have to be implemented in the object that you have set as the delegate for the NSTableView object.

[See Apple Docs on delegates in case you want a review of them] (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18)

like image 148
jLi Avatar answered Sep 23 '22 07:09

jLi