Cannot make NSTableView clickable

I am trying to make a simple NSTableView (text only) that I can click on cells to edit text. All the training materials and related questions suggest that this is an automatic behavior, but I cannot get it.

I have no problem linking my delegate and data sources; I can program all the cells, and I can figure out what to do with the new text that is entered when editing. ... I just can't open the text box for editing!

(NSTable columns are marked as editable in IB)

Thanks for any tips.

+6
source share
2 answers

In the delegate method of tableView: viewForTableColumn, I had to specifically configure each cell for editing.

It seems to work without problems after using several weeks, but I still think there should be a less time-consuming method.

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { NSTableCellView *cellView; if( [tableColumn.identifier isEqualToString:@"word"] ) { wordCellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self]; cellView = wordCellView; [cellView.textField setEditable:YES]; // Make Cell Editable! } } 
+6
source

You can do this in Interface Builder by selecting a cell in the text box, and then use the Attributes Inspector to scroll down to the drop-down menu called “Behavior” and select “Editable”.

Only this will allow you to double-click on individual cells and make them editable by TextField.

For the changes you make to take effect, you will also need to implement the following method from the NSTableViewDelegate protocol: - (void) tableView: setObjectValue: forTableColumn: string:

[Cm. Apple Docs for this feature] ( 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 should be implemented in the object that you set as the delegate for the NSTableView object.

[See Apple docs on delegates if you want to view them] ( https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/ TP40002974-CH7-SW18 )

+7
source

All Articles