2012-04-21 84 views
3

我试图通过订阅WillDisplayCell事件来更改NSTableView中的行颜色。 首先,这个事件从未被提出。 其次,NSTableView中的字段不再可选,因此功能被破坏。 对于不起作用的SelectionChanged事件,可以观察到相同的行为。MonoMac事件 - 更改NSTable行的颜色

//NSTableView table 
table.SelectionDidChange += SelectionChanged; 
table.WillDisplayCell += WillDisplay; 

如何使这些事件工作?

谢谢!

+0

你提到同样注意到了同样的问题只能用SelectionDidChange。 – eaglestorm 2012-08-07 23:49:36

回答

1

不知道,如果你解决了这个与否,但对于其他人谁遇到这样的解决方案是增加类似的tableview例如观察员,即

arrayController.AddObserver(this,new NSString("selectionIndexes"),NSKeyValueObservingOptions.New,IntPtr.Zero); 

然后覆盖观察值的方法

public override void ObserveValue (NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context) 
{ 
... 
} 

这可以工作,但NSTableviewBinding示例使用了一种不同的方法,但是这对我不起作用。

+0

谁是arrayController? – 2014-05-13 15:51:49

0
在AwakeFromNib寄存器观察者

像这样

NSNotificationCenter.DefaultCenter.AddObserver (this, new Selector ("selectionChanged"), "NSTableViewSelectionDidChangeNotification", yourTableView); 

然后处理选择的变化,像这样

[Export("selectionChanged")] 
public void SelectionDidChangeNotification(NSObject o){ 
    ... 
}