Remove custom views from NSOutlineView

  • I'm having some problems with NSOutlineView. I'm trying to create a
    'filters list'. Basically, the outline view lists a filters, each of
    which is a custom NSCell which loads a view from the NIB. Each filter
    has one 'child' and a single level of expansion so that when you
    expand a filter in the list, the child row contains another view from
    the NIB, this time displaying the actual controls etc associated with
    that filter type. So we have two distinct views: a 'header view' which
    contains the filter name and a delete button, and a 'content view'
    which contains it's widgets.

    Filter 1 - header view (collapsed)
    Filter 2 - header view (expanded)
      - content view

    I'm using the standard data source/delegate methods and I got that
    working. The problem is the views are disappearing when there are
    multiple rows and are not removed when a row is collapsed. I'm aware
    of the removeFromSuperviewWithoutNeedingDisplay method (swiped from's examples, which inspired me) and have used it similarly in
    NSTableViews when calling reloadData thus

      while ([[mTableView subviews] count] > 0) {
      [[[mTableView subviews] lastObject]

    But I can't get it working for the outline view. I tried using the
    outlineViewItemDidCollapse notification to instruct each view to
    remove itself when collapsed but still no joy.

    - (void)outlineViewItemWillCollapse:(NSNotification *)notification
    id item = [[notification userInfo] valueForKey: @"NSObject"];

    else if ( [item isKindOfClass: [Filter class]] ) {
      [[item view] removeFromSuperviewWithoutNeedingDisplay];

    I've not found anything on the web. Any suggestions would be most
  • OK I think I know what's going wrong. I'm using NSViewController to handle
    each view in my custom table, but I was using the init() constructor rather
    than the initWithBundle...() constructor as described in the documentation.
    I was calling init and then calling setView:, passing in an outlet to the
    view in the nib. Now that I'm calling initWithBundle...() it seems to work

    The problem is this implementation assumes each view is in a seperate NIB
    with the FileOwner to the NSViewController and the single view outlet set. I
    really want to contain all my views in a single NIB. Is there any way to do
    this? I've got about 20 views and I don't want 20+ NIBs! No doubt I'm
    missing something here.
previous month december 2007 next month
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today