开发者

Access IB instantiated NSBox in MyDocument from another class?

I star开发者_运维问答ted with the View Swapping code from Hillegass's book Cocoa Programming for MAC OS X. This code uses a popup menu in MyDocument.nib to swap ViewControllers using displayViewController in MyDocument.m partially shown below. I'm trying instead to use rows of a table in a ViewController to swap ViewControllers by calling displayViewController in MyDocument.m from the ViewController that generated the table:

- (void)displayViewController:(ManagingViewController *)vc
                   curBox: (NSBox *)windowBox
{
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
    NSBeep();
    return;
}
...

The problem I am having is when I call displayViewController from another ViewController I need to send along the Interface Builder instantiated NSBox in MyDocument.nib so that the view can be swapped inside the NSBox in MyDocument.m. So do to this I need to be able to access the Interface Builder instantiated NSBox in MyDocument.nib from another ViewController.

Does anyone know how to access the Interface Builder instantiated NSBox in MyDocument.nib from another ViewController?

EDIT:

I've made some progress. The view hierarchy is:

 Window
   ContentView
     NSBox

I've been able to get the top level Window and the current ContentView with the following:

NSWindow *w = self.view.window;
NSView   *v = [w contentView];

but I still haven't figured out how to get the NSBox that is within the ContentView. I've tried the following but they haven't worked:

NSBox    *b = [v container];
NSBox    *b = [v content ];

Anyone have an idea?


I found the solution. The NSBox is a subview of the ContentView. So the following works:

NSWindow *w   = self.view.window;
NSArray  *va  = [[w contentView] subviews];
NSBox    *b   = [va objectAtIndex:0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜