Outline view spontaneously collapsing

  • Hi, all,
    I have an application with an outline view that spontaneously collapses all
    items on certain changes to my data for no apparent reason.  (My outline
    view delegate receives no notifications that the collapse is about to occur,
    and I have no code that performs such a collapse.)  I've reworked the data
    model about three times over to minimize the value-change notifications that
    I thought could be causing the view to reset its data, and the view seems
    even more prone to inappropriate collapse.

    Some details:

    - It's a CoreData application, but I'm using a NSTreeController in Class
    mode because the underlying CoreData objects are of different types, and I
    found it easier to use "proxy" classes to front the underlying objects.

    - My typical views so far are bound to a contentArray of a single (proxy)
    object which is the root of a tree of other proxy objects, all of which are
    one of two classes.

    - The operation in question requires me to send KVO notifications that the
    property bound to the NSTreeController's contentArray binding as well as the
    child key path of every non-leaf node (to force a re-evaluation of the
    content), but I have gone to great lengths to assure that minimal changes
    are made to the actual properties (i.e., I leave the proxy objects and
    arrays intact unless the content has really changed), but, as I mentioned,
    the more careful I am about actually changing content objects, the more
    likely a spontaneous collapse is to occur.

    I suspect I'm sending some other notification that's triggering the outline
    view to decide that the content has changed, but I've spend so much time
    wallowing in this I feel like I've exhausted the possibilities, which means
    I'm probably overlooking something fundamentally obvious that will make me
    feel stupid when someone points it out, but I'm more than willing to face
    the humiliation at this point.

    Any suggestions on what to look for?

    TIA,
    Doug K;
  • > I have gone to great lengths to assure that minimal changes are made
    > to the actual properties (i.e., I leave the proxy objects and arrays
    > intact unless the content has really changed)

    The only thing I can think of is that NSOutlineView requires objects
    to be pointer equal between changes for the expanded state to me
    maintained between updates. Have you confirmed that this is the case?

    - Keith
  • On 9/14/07, George Orthwein <george.o...> wrote:
    >
    > This may be helpful:
    > http://www.corbinstreehouse.com/blog/?p=13
    >

    George,

    The link contains a lot of information I found helpful, but my code is still
    not working.  Here's a distillation of what I think is relevant:

    - My outline view uses a NSTreeController, which is bound to a window
    controller's "contentArray", an NSArray which currently contains only the
    root node of the tree I'm trying to display.

    - The problem I'm observing occurs when I change external criteria for which
    children of the non-leaf nodes in the view are displayed.  I need to force
    the view and its data source to recalculate its content.

    - If I send a key-value notification that "contentArray" has changed, the
    outline view collapses even if the "contentArray" and the children of the
    root node don't change at all.

    - If I send a "rearrangeObject" message to the NSTreeController, the outline
    view collapses even if I suppress all changes to the actual objects in the
    model.

    - If I don't do either of the above, by tree doesn't get updated.  (In fact,
    I don't think I can get the view content to update correctly unless I send
    will/did-UpdateValueForKey notifications for the controller's top-level
    content and child keys.

    - I've considered the possibility that I should try to use the view's
    autosave settings, but once I got them to work, they don't seem to apply to
    transient changes like the ones I'm making here.

    Any advice is welcome...

    TIA!!

    Doug K;
  • Hmmm, unfortunately I don't really have any ideas, but my knowledge
    in this area is quite limited.

    I can say that in one of my test projects calling rearrangeObjects on
    the tree controller does collapse all the items. Calling reloadData
    on the view leaves the expansion states intact.

    I would tend to think you shouldn't have to manually send KVO
    notifications that the contentArray has changed... it might be
    helpful to give more detail on exactly how you are changing the
    contentArray. As described it sounds like maybe you are filtering out
    different children so essentially different ones are being displayed?
    I'd expect the parent to collapse in that case, but it sounds like
    unrelated parents are collapsing?

    George
  • George, I think you said the magic word: reloadData.
    I overlooked it because I've been studying the API for NSOutlineView and
    neglecting the methods inherited from NSTableView, causing me to rely way
    too heavily on rearrangeObjects.

    I've kind of mangled my code trying to implement some workarounds, so it'll
    take me a little work to clean it up, but I think I'm on the right track
    now.

    Thanks to the advice already received, my management of the view's model is
    much cleaner, minimizing replacement and modification of the model objects
    and eliminating the extra KVO notifications, so I think I'm on the right
    track.

    Thanks very much for the pointers and your time!

    Doug K;

    On 9/18/07, George Orthwein <george.o...> wrote:
    >
    > Hmmm, unfortunately I don't really have any ideas, but my knowledge
    > in this area is quite limited.
    >
    > I can say that in one of my test projects calling rearrangeObjects on
    > the tree controller does collapse all the items. Calling reloadData
    > on the view leaves the expansion states intact.
    >
    > I would tend to think you shouldn't have to manually send KVO
    > notifications that the contentArray has changed... it might be
    > helpful to give more detail on exactly how you are changing the
    > contentArray. As described it sounds like maybe you are filtering out
    > different children so essentially different ones are being displayed?
    > I'd expect the parent to collapse in that case, but it sounds like
    > unrelated parents are collapsing?
    >
    > George
    >
    >
previous month september 2007 next month
MTWTFSS
          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