问题
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