Re: Cocoa Bindings Question(s)
Re: Cocoa Bindings Question(s)
- Subject: Re: Cocoa Bindings Question(s)
- From: Mont Rothstein <email@hidden>
- Date: Fri, 16 Jul 2004 16:23:55 -0700
On 7/16/04 1:27 PM, "email@hidden" <email@hidden> wrote:
>
So now, I'm looking at mmalc's Bookmarks example from his page
>
(http://homepage.mac.com/mmalc/CocoaExamples/controllers.html)
>
the Drag and Drop example. He has some routines in the MyDocument.m document
>
class file that I don't know why they are there or how they are being called.
>
They are labeled "bookmarksArray accessors". They do include the getter and
>
setter, similar to the ones I added, but also include a bunch of others:
>
>
countOfBookmarksArray:
>
objectInBookmarksArrayAtIndex:
>
insertObject:inBookmarksArrayAtIndex:
>
removeObjectFromBookmarksArrayAtIndex:
>
replaceObjectInBookmarksArrayAtIndex:
Those methods are Key-Value Coding accessor methods. There is a default
implementation in NSObject, so your frequently don't have to implement them.
You can implement them if you want to modify the behavior of one of them or
if the attribute isn't actually an array, but you want it to be treated as
such.
If you haven't already seen them:
KVC Reference:
http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueCoding/ind
ex.html#//apple_ref/doc/uid/10000107i
I found this good as well:
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/inde
x.html#//apple_ref/doc/uid/10000167i
>
I do see where some of these routines are called from his subclass of the
>
NSArrayController (DNDArrayController) (in response to some drag and drop
>
routines), but the insertObject routine is called when the Add button is
>
clicked, and I'm not sure why! I tried adding a similar call to the (Mike
>
Beam) sample, but it's not called when I click it's Add button.
Add causes a call of the insertObject:inBookmarksArrayAtIndex: method
because the Bookmarks array is bound to the array controller. When the Add
button tells the array controller to insert an object the binding inserts on
object (via KVC) in the bookmarks array.
I'm not sure why the method you added isn't called but I believe you have to
implement all of the accessor method for an array if you implement any of
them.
I hope that helps.
-Mont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.