Pass an NSMutableArray to a NSWindowController

南笙酒味 提交于 2019-12-13 04:06:14

问题


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.


回答1:


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"];



回答2:


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];


来源:https://stackoverflow.com/questions/7112903/pass-an-nsmutablearray-to-a-nswindowcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!