Eim*_*tas 15 cocoa subclass nsarraycontroller cocoa-bindings
我正在努力改进我的KVC/KVO/Cocoa-Bindings-fu,并想知道继承NSArrayController的原因是什么?
Max*_*ann 17
我有一个自定义NSArrayController子类,执行一大堆任务.我选择在那里实现这些东西,因为我可以享受绑定和东西的完全舒适.以下是我现在使用的内容:
是的,依此类推.基本上这一切都归结为这个本质:子类NSArrayController,如果你想要不同的数据输出
马克斯
使用带有表视图的数组控制器时,我喜欢做的一件事是覆盖add:以发布通知,以便选择新项并立即打开进行编辑.我实际上刚刚在CocoaDev发布了这个:
// 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]
}
Run Code Online (Sandbox Code Playgroud)
当然,可以与不是NSArrayController子类的控制器类似; 这只是我想出的第一种方式.