I am trying to improve my KVC/KVO/Cocoa-Bindings-fu and was wondering what could be the reasons to subclass the NSArrayController?
I have a custom NSArrayController subclass that perform a whole bunch of task. I chose to implement these things there because I can then enjoy the full comfort of bindings and stuff. Here's what I use this now for:
Yeah, and so on. Basically this all boils down to this essence: subclass NSArrayController if you want different data out than you put in
Max
One thing I like to do when using an array controller with a table view is to override add:
to post a notification so that the new item is selected and open for editing right away. I actually posted this over at CocoaDev a while ago:
// Subclass of NSArrayController
- (void)awakeFromNib
{
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(objectAdded:)
name: @"Object Added"
object: self]
}
- (void)add: (id)sender
{
[super add: sender]
NSNotification * note = [NSNotification
notificationWithName: @"Object Added"
object: self]
// The add method doesn't really take effect until this run loop ends,
// (see NSArrayController docs) so the notification needs
// to wait to post. Thus, enqueue with NSPostWhenIdle
[[NSNotificationQueue defaultQueue] enqueueNotification: note
postingStyle: NSPostWhenIdle]
}
- (void)objectAdded: (NSNotification *)note
{
// when the notification finally arrives, tell the table to edit
[[self contentTable] editColumn:0
row:[self selectionIndex]
withEvent:nil
select:YES]
}
Of course it's possible to do similar with a controller that's not an NSArrayController
subclass; this is just the first way I figured out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With