Skip navigation.
 
mlRe: Simple bindings problem
FROM : Martin Linklater
DATE : Sun Jan 06 09:22:19 2008

On 6 Jan 2008, at 00:24, mmalc crawford wrote:

> Well, how do you do it currently?


Currently in my test app I have an NSPopUpMenu, an NSTextField next to 
it, and two NSButtons (Add and Remove). My NSPopUpMenu is bound to my 
array controller, which has it's contents initialised in my 
AppControllers init method. This inits the NSPopUPMenu with 4 strings. 
I have the Add and Remove buttons triggering the insert: and remove: 
actions of the array controller.

>
> How do you want to do it?


What I would like is for whatever string I enter into the NSTextField 
to be used as the string for the new NSPopUpMenu entry.

>
> What opportunities do the controller classes give for customising 
> the process?


This is the bit I'm investigating. I had hoped there would be a way 
for the NSArrayController's 'insert' action to take a parameter 
setting the contents of the newly created object - kind of a 'use this 
object to initialise the new object' setting in the bindings pane. But 
it seems like this is not possible using IB alone - all you can do is 
insert a new, empty object into the array.

After googling for a bit last night I found this on CocoaDev:

There are a number of ways to customize new objects that get added to 
the array:

Subclass NSArrayController and override newObject or addObject.
Register as an observer of the array's key in the providing object, 
using KeyValueObserving. You will be informed when a new object is 
added to that array, which you can then modify (the new object will be 
passed to you.)
In the object providing the content array, implement the 
KeyValueCoding array methods, one of which is 
insertObject:in<Key>AtIndex?:.

So I'm looking at implementing these suggestions... I just thought 
there may be a way to do it without writing any code... just by 
setting things up in IB.

Thanks.

>
>
> mmalc
>

Related mailsAuthorDate
mlSimple bindings problem Martin Linklater Jan 5, 10:58
mlRe: Simple bindings problem Martin Linklater Jan 5, 12:46
mlRe: Simple bindings problem Martin Linklater Jan 5, 23:02
mlRe: Simple bindings problem mmalc crawford Jan 6, 01:24
mlRe: Simple bindings problem Martin Linklater Jan 6, 09:22
mlRe: Simple bindings problem mmalc crawford Jan 6, 10:58
mlRe: Simple bindings problem Martin Linklater Jan 6, 14:13