Re:NSArrayController's "selectionIndex" weirdness
Re:NSArrayController's "selectionIndex" weirdness
- Subject: Re:NSArrayController's "selectionIndex" weirdness
- From: Johnny Lundy <email@hidden>
- Date: Fri, 11 Apr 2008 14:19:17 -0400
On Apr 10, 2008, at 19:09, Quincey Morris wrote:
Thanks a bunch, Quincey.
That worked fine. I was going by NSArrayController's documentation
that its "selectionIndex" method returned an NSUInteger. Either that
is wrong or the NSButton wraps it in an object wrapper when it uses
the "Argument" binding, I guess.
This reduces the code I have to write by a bunch.
Now I am running into the "View Doesn't Update When Model Is Changed"
issue that Apple lists under "Troubleshooting Cocoa Bindings", in that
the array element gets removed by my "removeObjectAtIndex: [theIndex
integerValue]", but that is apparently not KVO-compliant.
I read the suggested text and sample code for proxy collections and so
forth, but still don't quite get what I am supposed to provide as far
as accessor methods to get the array to be observed for deletions and
additions of objects.
The suggested methods refer to adding accessors that use value:forKey,
but I do not have a key for an array element - all I have is the
selectionIndex. So I am not clear how to do it. In fact, I guess I
don't get how value:forKey works with an array at all, since only
dictionaries have keys.
Can someone point me to an example of using removeObjectAtIndex: and
having KVO take care of updating the NSTableView? Thanks. I have
already declared the model array as mutable, @property (readwrite,
copy) and @synthesize.
Johnny
ATM Software
- (void) nightKill:(NSUInteger) theWhackedOne
{
NSLog(@"SelectionIndex=%@",theWhackedOne);
[playerArray removeObjectAtIndex:theWhackedOne];
return;
}
The array controller is sending you a NSNumber whose value is the
selection index. That's why it NSLogs correctly with the %@ (object)
format specifier.
You need:
- (void) nightKill:(NSNumber *) theWhackedOne
{
NSLog(@"SelectionIndex=%@",theWhackedOne);
[playerArray removeObjectAtIndex:[theWhackedOne integerValue]];
return;
}
_______________________________________________
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