gpt4 book ai didi

macos - 如何在基于 View 的 NSOutlineView 中自定义显示单元

转载 作者:行者123 更新时间:2023-12-03 16:02:30 25 4
gpt4 key购买 nike

我正在尝试在基于 View 的 NSOutlineView 中自定义显示箭头外观。我看到推荐使用

- (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item

委托(delegate)方法来实现它。问题是由于某种原因没有调用该方法。我有 2 个自定义单元格 View - 一个用于项目,第二个用于标题项目。基于 View 的大纲 View 可能不调用此方法吗? Lion 中可能有什么东西坏了吗?

请透露一些信息。

最佳答案

解决方案1:

子类 NSOutlineView 并覆盖 makeViewWithIdentifier:owner:

- (id)makeViewWithIdentifier:(NSString *)identifier owner:(id)owner {
id view = [super makeViewWithIdentifier:identifier owner:owner];

if ([identifier isEqualToString:NSOutlineViewDisclosureButtonKey]) {
// Do your customization
}

return view;
}

对于源列表,请使用NSOutlineViewShowHideButtonKey

解决方案2:

界面生成器

按钮已添加到列中,并且标识符设置为 NSOutlineViewDisclosureButtonKey

enter image description here

来自 NSOutlineView.h 的官方文档

/* The following NSOutlineView*Keys are used by the View Based NSOutlineView to create the "disclosure button" used to collapse and expand items. The NSOutlineView creates these buttons by calling [self makeViewWithIdentifier:owner:] passing in the key as the identifier and the delegate as the owner. Custom NSButtons (or subclasses thereof) can be provided for NSOutlineView to use in the following two ways:
1. makeViewWithIdentifier:owner: can be overridden, and if the identifier is (for instance) NSOutlineViewDisclosureButtonKey, a custom NSButton can be configured and returned. Be sure to set the button.identifier to be NSOutlineViewDisclosureButtonKey.
2. At design time, a button can be added to the outlineview which has this identifier, and it will be unarchived and used as needed.

When a custom button is used, it is important to properly set up the target/action to do something (probably expand or collapse the rowForView: that the sender is located in). Or, one can call super to get the default button, and copy its target/action to get the normal default behavior.

NOTE: These keys are backwards compatible to 10.7, however, the symbol is not exported prior to 10.9 and the regular string value must be used (i.e.: @"NSOutlineViewDisclosureButtonKey").
*/
APPKIT_EXTERN NSString *const NSOutlineViewDisclosureButtonKey NS_AVAILABLE_MAC(10_9); // The normal triangle disclosure button
APPKIT_EXTERN NSString *const NSOutlineViewShowHideButtonKey NS_AVAILABLE_MAC(10_9); // The show/hide button used in "Source Lists"

关于macos - 如何在基于 View 的 NSOutlineView 中自定义显示单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11127764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com