Search code examples
cocoamacospositioningframenssplitview

Incorrect NSTableView frame within an NSSplitView


Within my Mac app I've setup two NSSplitViews to create a Mail-style interface (with the first ScrollView used to create a vertical separator, and the second nested within the first, to create the horizontal separator). To illustrate the interface, I've created the following diagram:

alt text http://img96.imageshack.us/img96/1091/setupn.png

To illustrate the setup further, here's an annotated snap of my view hierarchy:

alt text http://img714.imageshack.us/img714/8153/yayaj.png

The issue I'm having is that, when trying to grab the frames of two NSTableView's hosted within portion B and C of my NSSplitView, I receive relative coordinates. Here's the code I'm using:

NSRect aTableViewFrame = [aTableView frame];
NSRect bTableViewFrame = [bTableView frame];
NSLog(@"%@ %@", NSStringFromRect(aTableViewFrame), NSStringFromRect(aTableViewFrame));

Here's the output I see:

{{0, 0}, {760, 143}} {{0, 0}, {760, 392}}

As you can see from the returned NSRect values, I'm given the correct width and height of the NSTableView, but what I'm really after is their position relative to the parent NSSplitView. Of course, I could use (a number of) IBOutlets and construct the correct rect value myself, but what I'm really looking for is an easy way to grab the frame of the NSTableViews relative to either the parent NSSplitView or the containing Window.


Solution

  • If you have the split view, or get it by setting up an outlet, you could use convertRect:fromView:. Or to get window-relative coordinates, you could use convertRectToBase:. Bear in mind that the table's frame would be relative to its superview, so you'd use something like [[bTableView superView] convertRectToBase: bTableViewFrame].