NSArrayController & bindings: next hurdle.
NSArrayController & bindings: next hurdle.
- Subject: NSArrayController & bindings: next hurdle.
- From: Colin Howarth <email@hidden>
- Date: Wed, 23 Sep 2009 04:21:09 +0200
Hi, just when I thought it was safe to go back into the water...
So, I have an NSArrayController (in IB). Its Content Array is bound to
an NSMutableArray (of 'Element') instance in my AppDelegate.
If I alter an Element in a KVC way, then the Array Controller notices
this and the NSTableView is updated correctly.
I connected some NSButtons to the add:, insert: and remove: actions of
the NSArrayController. If I click any of these, the app crashes.
I had a look at some sample code (Aperture Edit Plugin - Borders &
Titles, listed under 'remove:' in the NSArrayController Class
Reference) and was
astonished to find that the NSArrayController there isn't bound to
*any* array. The add and delete buttons there are connected to the
App, which then creates objects and simply asks the NSArrayController
to addObject: [the object] or remove: [whatever's selected]. So, in
this case, the Array Controller has its own internal anonymous array,
and is happy to add and delete from that.
Is it the case then, that if the NSArrayController is *bound* to an
external array, then that external bit of code (in my case my
AppDelegate) is responsible for adding and deleting items???
"NSObjectController and its subclasses are initialized with the method
initWithContent:, passing a content object or nil if you intend to use
the content bindings. You can explicitly set the content of an
existing controller using the setContent: method. It is far more
common to provide content for controllers by establishing a binding to
one of their exposed Controller Content bindings." (from the Cocoa
Bindings Programming Topics: Providing Controller Content)
I didn't pay too much attention to this, since my code doesn't
initialize the Controller - IB does that. In any case, it says "It is
far more common to provide content for controllers by establishing a
binding" which is presumably why the sample code doesn't do it :-)
Is there any hint that add: and remove: et al. won't work in the case
that a binding has been established?
Or are these still supposed to work, and there's something else wrong
with my code? <what code? I haven't got any code. I've got bindings
and icons in an IB window...>
*aaaargh*
from GDB:
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
(thank you GDB)
from asm:
#13 0x7fff824ba122 in -[NSApplication sendEvent:]
#12 0x7fff82584967 in -[NSWindow sendEvent:]
#11 0x7fff8266a135 in -[NSControl mouseDown:]
#10 0x7fff8269c1a3 in -[NSButtonCell
trackMouse:inRect:ofView:untilMouseUp:]
#9 0x7fff8266b68b in -[NSCell trackMouse:inRect:ofView:untilMouseUp:]
#8 0x7fff825e019d in -[NSControl sendAction:to:]
#7 0x7fff825e023e in -[NSApplication sendAction:to:from:]
#6 0x7fff826ee668 in -[NSArrayController remove:]
#5 0x7fff826ef868 in -[NSArrayController
_removeObjectAtArrangedObjectIndex:objectHandler:]
#4 0x7fff826efd87 in -[NSArrayDetailBinder
removeObjectFromMasterArrayRelationshipAtIndex:selectionMode:]
#3 0x7fff826f05ef in -[NSArrayDetailBinder
_performArrayBinderOperation:singleObject:multipleObjects:singleIndex:multipleIndexes:selectionMode
:]
#2 0x7fff82644fde in -[NSArrayDetailBinder
_refreshDetailContentInBackground:]
#1 0x7fff82645435 in _NSValueOfClassWithSpecialSpecificErrorMessage
#0 0x7fff823953cc in objc_msgSend_vtable4
So, once again, please unconfuse me...
--colin_______________________________________________
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