Re: Simple bindings problem
Re: Simple bindings problem
- Subject: Re: Simple bindings problem
- From: Martin Linklater <email@hidden>
- Date: Sun, 6 Jan 2008 08:22:19 +0000
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden