如何做一个NSOutlineView其中一些entires是按钮? [英] How can I make an NSOutlineView where some of the entires are buttons?
问题描述
我想创建一个NSOutlineView子类,其中一些条目看起来像按钮。它看起来像这样:
I want to create an NSOutlineView subclass where some of the entries look like buttons. It would look something like this:
+ Fruits
+ Organic
- Apples
- Bananas
[Add Item]
+ Non-organic
- Cherries
[Add Item]
[Add Item]
+ Vegetables
- Carrots
[Add Item]
所有[Add Item]都是按钮。
Where all of the "[Add Item]"'s are buttons.
我有一种感觉,这涉及到使用outlineView:willDisplayCell:forTableColumn:item:delegate方法?
I have a feeling this involves using the outlineView:willDisplayCell:forTableColumn:item: delegate method somehow?
推荐答案
您将需要在大纲视图的委托中实现 outlineView:dataCellForTableColumn:item:
方法,以便为需要按钮的行返回一个NSButtonCell,用于其他行的NSTextFieldCell。注意这个委托方法是在10.5中添加的,如果你需要支持10.4或更早版本,那么你需要一个自定义的NSTableColumn子类来覆盖 dataCellForRow:
方法。
You'll want to implement the outlineView:dataCellForTableColumn:item:
method in your outline view's delegate to return an NSButtonCell for the rows where you want a button, and an NSTextFieldCell for the other rows. Note that this delegate method was added in 10.5, if you need to support 10.4 or earlier, then you'll need to have a custom NSTableColumn subclass that overrides the dataCellForRow:
method.
这篇关于如何做一个NSOutlineView其中一些entires是按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!