Если вы используете NSOutlineViewDataSource, а не привязки, вы можете сделать это следующим образом:
- (void)iterateItemsInOutlineView: (NSOutlineView*)outlineView
{
id<NSOutlineViewDataSource> dataSource = outlineView.dataSource;
NSMutableArray* stack = [NSMutableArray array];
do
{
// Pop an item off the stack
id currentItem = stack.lastObject;
if (stack.count)
[stack removeLastObject];
// Push the children onto the stack
const NSUInteger childCount = [dataSource outlineView: outlineView numberOfChildrenOfItem: currentItem];
for (NSUInteger i = 0; i < childCount; ++i)
[stack addObject: [dataSource outlineView: outlineView child: i ofItem: currentItem]];
// Visit the current item.
if (nil != currentItem)
{
// Do whatever you want to do to each item here...
}
} while (stack.count);
}
Это должно обеспечить полный обход всех объектов, продаваемых вашим NSOutlineViewDataSource
.
К вашему сведению: если вы используете привязки какао, это не будет работать как есть. Если это так, то вы можете использовать аналогичный подход (то есть обход суррогатного стека) против NSTreeController (или чего-либо еще), к которому вы привязываетесь.
HTH