3

Is there a simple way to walk back up the NSView hierarchy (superview of superview of superview of nsview) to the main window or a point in between?

Thanks

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137

2 Answers2

5
NSView *aView = myView;
while ((aView = [aView superview])) {
    NSLog(@"%@", aView);
}
Francis McGrew
  • 7,264
  • 1
  • 33
  • 30
1

A view won't necessarily have anything to do with “the main window”, for any definition of that term, but you can get the window that a view is in by simply asking it.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • Thanks, I actually meant contentView of window but in reality I wasn't even going back that far up the chain... – PruitIgoe Dec 13 '11 at 14:25