Always show disclosure triangle in NSOutlineView even for empty records

I have an application that shows "chapters and pages" in a NSOutlineView

.

To make it clear to the user that "chapters" can contain "pages", I would like the outline view to always display a disclosure triangle for chapters, even if they have no pages (ie blank).

Here's an example:

enter image description here

Note that the first chapter is empty (no pages) and does not have a disclosure triangle.

I would like the triangle to be displayed so that when users click on it, they know it is a "container" element that can contain other elements.

I tried to implement various delegate methods, but was unable to get the disclosure triangle to display empty entries.

Sample project: https://www.dropbox.com/s/fdggjod78t0isjr/OutlineViewTest.zip?dl=0

+3


source to share


2 answers


Ok, now I see. You are using Cocoa Bindings, which assumes that some of the methods dataSource

should not be called. As shown in the NSOutlineViewDataSource man page

'- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item "

IMPORTANT

Although this method is marked @optional in the protocol, you must implement this method unless you provide data for the outline using Cocoa bindings.

Just try to implement it without Cocoa Bindings. Or, you might find a way to sneak into the binding process and figure out how to deny the disclosure button removal.

Yes, there is a third way. You can create MyTableCellView.xib and add your own disclosure button.

UPD



To determine which element should have a disclosure triangle exists Leaf

in the Attributes inspector tab Tree Controller

.

enter image description here

Don't forget to add model values ​​to your data like

@{@"title": @"Chapter 1 (empty)", @"isLeaf":@(NO)}

      

enter image description here

+3


source


You need to implement NSOutlineViewDelegate

outlineView:shouldShowOutlineCellForItem:

and return it YES.

- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item {
    return YES;
}

      

A "contour cell" is a disclosure triangle. You need this in addition to returning YES for isExpandable

.

The link says:



Returning NO calls frameOfOutlineCellAtRow:

to returnNSZeroRect

And the 1st answer here on how to change the triangle image indicates that the frame is used for both cells and view based view, so this method should work for both. (Note that this is the simpler answer.)

This wiki answer ... I suspect I missed something.

+1


source







All Articles