How can I make an NSOutlineView where some of the entires are buttons?

对着背影说爱祢 提交于 2019-12-22 17:42:20

问题


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]

Where all of the "[Add Item]"'s are buttons.

I have a feeling this involves using the outlineView:willDisplayCell:forTableColumn:item: delegate method somehow?


回答1:


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.



来源:https://stackoverflow.com/questions/482357/how-can-i-make-an-nsoutlineview-where-some-of-the-entires-are-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!