The following NSOutlineView*Keys are used by the View Based NSOutlineView to create the "disclosure button" used to collapse and expand items.
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"
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:
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.
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").
If you want to change also the position, than subclass your NSTableRowView and overwrite layout method
- (void)layout {
[super layout];
for (NSView * v in self.subviews) {
if ([v.identifier isEqual:NSOutlineViewDisclosureButtonKey]) {
v.frame = NSMakeRect(self.bounds.size.width - 44, 0, 44, self.bounds.size.height);
v.hidden = NO;
break;
}
}
}
and the code for the overwritten NSOutlineView
- (NSView *)makeViewWithIdentifier:(NSString *)identifier owner:(id)owner {
NSView * v = [super makeViewWithIdentifier:identifier owner:owner];
if ([identifier isEqual:NSOutlineViewDisclosureButtonKey] && ([v isKindOfClass:[NSButton class]])) {
MenuDisclosureButton * b = [[MenuDisclosureButton alloc] initWithFrame:NSMakeRect(0, 0, 44, 44)];
b.target = [(NSButton *)v target];
b.action = [(NSButton *)v action];
b.identifier = NSOutlineViewDisclosureButtonKey;
v = b;
}
return v;
}