How to add a series of rows to an NSTableView based on a view?

I am trying to get a table layout as shown below while working with view-based NSTableViews that were introduced in Lion.

There are many approaches described for cell based NSTableViews, for example. Submit cover column , but this is not really the case for view-based views.

The idea is that the table is populated with an array of objects in one (or more) columns spanning rows indicating that the objects share some common data. numberOfRowsInTableView:returns to the total number of elements (19 in the case of an attached image).

Has anyone tried something like this?

Markup

Groups / sections displayed using spanning rows

+5
2

, NSTableViews, NSScrollView. , ( ), Mac -

groupTableView, , . itemTableView, , . / if-else, , NSTableView , , .. , , :

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
    if (tableView == self.groupTableView) {
        NSUInteger firstRowIndexForGroup = ...;
        NSUInteger lastRowIndexForGroup = ...;
        CGFloat groupHeight = 0.0;
        for (NSUInteger currentRowIndex = firstRowIndexForGroup; currentRowIndex <= lastRowIndexForGroup; currentRowIndex++) {
            groupHeight += [self.itemTableView rectOfRow:lastRowIndexForGroup].size.height;
        }
        return groupHeight - [self.itemTableView intercellSpacing].height;
    } else {
        return self.itemTableView.rowHeight;
    }
}

-noteHeightOfRowsWithIndexesChanged: , , .

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    if (tableView == self.groupTableView) {
        GroupRowView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
        // configure view
        [tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
        return view;
    } else {
        ItemRowView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
        // configure view
        return view;
    }
}

. . , , , . , . , .

+5

NSOutlineView? .

0

All Articles