Re: Fastest way to "ExpandAll" in NSOutlineView
Re: Fastest way to "ExpandAll" in NSOutlineView
- Subject: Re: Fastest way to "ExpandAll" in NSOutlineView
- From: Corbin Dunn <email@hidden>
- Date: Tue, 6 Jun 2006 10:40:55 -0700
On Jun 6, 2006, at 9:51 AM, Corbin Dunn wrote:
On Jun 5, 2006, at 8:46 PM, Sanford Selznick wrote:
I'd like to expand-/collapse-all cells in an NSOutlineView
programmatically. The code below runs fine, but is slow once there
are more than a few hundred rows in the NSOutlineView.
for (int c = 0; c < [ov numberOfRows]; c++) {
id item = [ov itemAtRow:c];
if (expand) {
[ov expandItem:item];
}
else {
[ov collapseItem:item];
}
}
Any ideas how to make it faster?
First of all, sample your app to determine why it is slow. Then,
work on those issues to actually make the expansion faster.
However, expanding all the root items in an OV has some side
effects; namely, after each expandItem, the OV attempts to tile
itself to adjust for the new item. Since you know you are expanding
all the items, you can implement some code in a subclass that would
disable tiling, such as:
1. Subclass NSOutlineView and add an iVar named "_disableTiling".
Write accessors for it.
2. Override tile and do something like this:
- (void)tile {
if (_disableTiling) return;
[super tile];
}
3. Before your loop code write:
[ov disableTiling];
// loop to expand
[ov enableTiling];
(or something like that).
That should speed things up. Note that I am aware of this particular
issue in NSOutlineView and will address it.
I should also note the logic error in this code:
for (int c = 0; c < [ov numberOfRows]; c++) {
id item = [ov itemAtRow:c];
if (expand) {
[ov expandItem:item];
}
else {
[ov collapseItem:item];
}
}
After an item is expanded, the number of rows will change...so the
loop doesn't do quite what you want. I would recommend something like
this pseudo-code:
for (each item in my root items) {
[outlineView expandItem:item expandChildren:(yes/no)]
}
-corbin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden