NSArrayController - Mutability lost?
NSArrayController - Mutability lost?
- Subject: NSArrayController - Mutability lost?
- From: Diggory Laycock <email@hidden>
- Date: Sat, 16 Apr 2005 14:50:18 +0100
Hello there,
I'm a bit new to bindings an have a question.
I'm having a slight problem with an NSArray controller.
I have an class which is a preference pane's main class - let's call
it MyPrefPane. It has an NSMutableArray called 'tickets'.
I also have an NSArrayController, whose contentArray is bound to the
tickets array of the MyPrefPane class.
The NSArrayController is reponsible for displaying the tickets in an
NSTableView in the prefpane.
I need to add and remove tickets from the tickets array
programatically 'behind the controller's back' - so I would have
thought that using the insertIntoTickets: and
removeObjectFromTickets:atIndex: accessors in the MyPrefPane class
would be suitable - since they are observable by the ArrayController.
However- if I try and alter the mutableArray directly in these methods
I get exceptions - the MutableArray has turned into an immutable
one....
Is this right? Do the bindings alter my model's property's class
behind my back?
I currently work around this by making a mutable copy of the (now
immutable) tickets array - altering that, then resetting the 'tickets'
instance var to the mutable copy.
It seems inefficient to swap out the whole array - am I going about it
all wrong? It also means that the arrayController's selectionIndex
jumps back to zero when an object is removed from the array. I can
cache the old selectionIndex of the ArrayController, and reset it after
swapping out the array - but this seems a bit like glue code... :)
Thanks in advance for any help,
Diggory Laycock
-----------------------
http://www.monkeyfood.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden