NSArrayController add: action

I’m writing an application based on Chapter 7: A Class of Our Own from Shane Stanley’s book. I have everything hooked up (i.e., bindings) and everything works as it should.

My custom class has multiple properties. I have a single-column table that displays one of the class’ properties. (It is a sidebar, similar to iTunes, iPhoto and alike.)

My question is in regards to the NSArrayController’s add: action. When clicking on the button that is connected to the add: action a new Class object is created. However it is not selected in the table. I saw the select inserted objects option for the array controller but that selects everything in the table when the application is first launched. (Right now I’m generating test data in the main delegate’s applicationWillFinishLaunching_ handler.)

I’d like to have the new object selected in the table and ready for editing. Am I better off writing my own add: action or is there something I can set in IB? I haven’t found anything obvious in IB nor have my searches here proved fruitful.

Thanks in advance,
Brad Bumgarner

Model: Macbook (mid 2010)
AppleScript: xCode 3.2.6
Browser: Safari 7536.25
Operating System: Mac OS X (10.7)

You can use setSelectsInsertedObjects_ in code rather than the checkbox in the UI, which means you can have it off until after the initial data is loaded. Otherwise you will need to track the selection indexes yourself.

Thanks Shane,

I did discover setSelectsInsertedObjects_ and set it to false before loading the initial data and then set it to true afterwards and it works as advertised. I have also found that applications such as Mail and iTunes typically do a lot more than add an object to the sidebar and make it ready to accept keyboard input. I’ll probably write my own “add” method.

On a side note, I really like the idea of custom classes. I may need to do a major re-write of a pretty large application I wrote earlier. That app. has an array of dictionaries. There are 32 dictionaries in the array and each dictionary has 70+ properties. Turning those dictionaries into class objects makes so much more sense.

Thanks again,
Brad Bumgarner

Model: Macbook (mid 2010)
AppleScript: xCode 3.2.6
Browser: Safari 7536.25
Operating System: Mac OS X (10.7)