Re: Cocoa Bindings Question(s)
Re: Cocoa Bindings Question(s)
- Subject: Re: Cocoa Bindings Question(s)
- From: mmalcolm crawford <email@hidden>
- Date: Fri, 16 Jul 2004 19:19:59 -0700
On Jul 16, 2004, at 5:51 PM, email@hidden wrote:
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.
Thanks. Makes sense. I guess I was just wondering why he was using the
items just to insert and/or remove items. It looks like the routines
are just
doing the default action.
The methods and the reasons for using them are described further down
the page:
<
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
"Programmatic modifications to arrays not noticed by table view"
and a reference given to the documentation:
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueCoding/Concepts/AccessorConventions.html>
(see "Indexed Accessor Patterns for To-Many Properties").
To summarise: if you don't implement them, then:
(a) If you modify the array directly, the array controller (and hence
table view) won't notice;
(b) The whole array is replaced whenever you add or remove an item...
It's easy enough to add logging messages to see what's happening:
- (id)objectInBookmarksArrayAtIndex:(unsigned int)index {
NSLog(@"objectInBookmarksArrayAtIndex");
return [bookmarksArray objectAtIndex:index];
}
- (void)insertObject:(id)anObject inBookmarksArrayAtIndex:(unsigned
int)index
{
NSLog(@"insertObject");
[bookmarksArray insertObject:anObject atIndex:index];
}
Try also commenting out the indexed accessors and logging
setBookmarksArray:
- (void)setBookmarksArray:(NSMutableArray *)newBookmarksArray
{
NSLog(@"setBookmarksArray:");
if (bookmarksArray != newBookmarksArray)
{
[bookmarksArray release];
bookmarksArray = [newBookmarksArray mutableCopy];
}
}
2004-07-16 20:48:15.089 Bibliotecha[2412] ***
-[NSKeyValueSlowMutableArray insertObject:atIndex:]: value for key
booksList
of object 0x32d650 is nil
It looks like you're trying to add a nil object to the array...
mmalc
_______________________________________________
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.