Re: NSOutlineView force expansion/refresh?
Re: NSOutlineView force expansion/refresh?
- Subject: Re: NSOutlineView force expansion/refresh?
- From: Corbin Dunn <email@hidden>
- Date: Thu, 17 Jul 2008 07:59:25 -0700
On Jul 16, 2008, at 3:22 PM, Michael Hanna wrote:
I'm using observeValueForKeyPath:ofObject:change:context: to detect
when a change occurs in my data model. When a non-leaf node gets
added, the outline view draws the new item, but in an unexpanded
state. I try this code:
[m_rulesOutlineView noteNumberOfRowsChanged];
This is the wrong method to call. This just informs the table that the
number of rows may have changed, but in reality, the internal data
structures aren't updated. You need to call:
-reloadItem:reloadChildren:
passing in the parent item for which you added the child to.
// expand all items in outline view
This code below is also wrong on a several points. Let me clarify what
happens so you have a better understanding:
int c;
for (c = 0; c < [m_rulesOutlineView numberOfRows]; c++)
{
id item = [m_rulesOutlineView itemAtRow:c];
[m_rulesOutlineView expandItem:item];
This will expand the item, or try to expand it, even if the item isn't
expandable. You should check to make sure the item is expandable.
After expanding the item, the -numberOfRows will change, and you'll be
iterating the children of that newly expanded item (probably not what
you wanted).
[m_rulesOutlineView
setNeedsDisplayInRect:[m_rulesOutlineView rectOfRow:c]];
This just redisplays the item, requesting the cell to redraw. It
doesn't update any properties on the item. You should call -
reloadItem: if you want to have it update properties (ie: children,
being expandable, the item associated with that row, etc).
}
in order to expand the new item.
To expand all items, on Leopard, it is easiest to do:
- (void)expandItem:nil expandChildren:YES
that won't work on Tiger. If you have to release against tiger. You
should instead iterate through all children of the root and expand
them, passing YES to expandChildren. But, for your case, this isn't
what you want. You only want to expand the new item.
The new item expands(i.e. the
triangle points downward) but the leaf nodes aren't actually drawn.
The user has to undisclose, then disclose the new triangle in order to
see the children.
I have tried calling this code in the next event loop by doing this:
[self performSelector:@selector(refreshRulesTreeView)
withObject:nil afterDelay:0.0];
It's hard to say if that would even help; we would need to see the
contents of refreshRulesTreeView. Note that
performSelector..afterDelay: can subtly introduce bugs, and I don't
recommend using it unless you really need to.
For example, the line above won't work in a modal panel. You'd have to
pass in the proper run loop modes.
to no avail. Also, calling -reloadData results in an assertion in
NSOutlineView.m ...
What assertion?
corbin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden