开发者

Pass an NSMutableArray to a NSWindowController

开发者 https://www.devze.com 2023-03-29 06:38 出处:网络
So I am creating a NSWindowController like so: if ( summaryWindow ) { [summaryWindow release]; } // end if

So I am creating a NSWindowController like so:

if ( summaryWindow ) {
    [summaryWindow release];
} // end if
summaryWindow   = [[SummaryWindowController alloc] init];

I am then passing this object an array that I will 开发者_开发百科be using for a NSTableView

[ summaryWindow setGlobalStatusArray:globalStatusArray];

Once that object is created, I realize I have don't know how to do something fundamental which is to link the newly created object actions and outlets. If I create a object in the xib, and link up the methods, I can run an action but I don't have access to the array because the xib created a separate instance of the NSWindowController, so how would one programmatically create the NSWindowController but also pass an array to it.


You just have to initialize the windowcontroller properly. [[SummaryWindowController alloc] init]; just creates an empty window controller that doesn't know its window an so on. You can load it with its xib file. Do it like this:

summaryWindow   = [[SummaryWindowController alloc] initWithWindowNibName:@"YourWindowNIB"];


So I just ended up doing this via NSNotifications, and passing the Information via the userInfo.

// Register for notifications on Global Status Array updates
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reloadTableBuffer:) 
                                                 name:StatusUpdateNotification
                                               object:nil];

Like so:

- (void) reloadTableBuffer:(NSNotification *) notification
{
    if(debugEnabled)NSLog(@"DEBUG: Was Told to Reload Table Buffer...");
    NSDictionary *globalStatusUpdate = [notification userInfo];
0

精彩评论

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

关注公众号