NSTableView Links How to Add a String

I am working on an application with this interface (sorry that the language is Dutch):

http://www.flickr.com/photos/pluueer/5756159100/

The add function (including four NSTextFields) under the NSTableView is being transferred to the worksheet someday, but so far this is normal. I set the bindings according to the tutorial (http://cocoadevcentral.com/articles/000080.php), but the tutorial doesn’t indicate how to add rows as I want (just adds an empty row that you need to edit in NSTableView )

I have a link between the “Voeg toe” button (Dutch for “Add”) and the array controller. But after clicking, I get a message:

2011-05-28 23:37:56.149 Hop Calc[4345:a0f] -[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (0) not equal to number of keys (4)

This makes sense because I have not implemented anything to add rows, but I just don't know how to do this.

+3
source share
1 answer

"Add a row to the table" is the wrong way to think about it. Your table represents the collection, and the controller provides information to the table, mediating between the table (view) and assembly (model). Since you mentioned bindings, the collection is probably controlled by NSArrayController. So you want to add a new array (of the type that your array controller controls) to the array of contents of the array controller.

The easiest way: connect the "Add" button to the -add: NSArrayController action. It will add an empty string.

, "" - . , , ( ), , , NSArrayController, -addObject: ( , a -rearrangeObjects, ).

+5

All Articles