I'm really new in Cocoa/Obj-C programming.
I have fairly simple app (target platform Mac OSX 10.5 & 10.6), my background is C/C++ system programming.
I have a main Window with some text fields, buttons, properties etc. I setup outlets and actions (hopefully correctly). Additional window declared in another NIB is loaded upon one of the button clicks:
- (IBAction) openSettings: (id) sender
{
ConfigurationWindowController * wc=[[ConfigurationWindowController alloc] initWithWindowNibName:@"Configuration"];
[wc showWindow:self];
}
New window is being loaded and shows up.
I need to do following things : 1) pass some string params to the second ("child") window 2) receive this params back to the main window when second window is closing.
I'm not sure what is a correct way to do this in Cocoa.
@sergio : Many thanks for your response! In my "child" window I store pointer to the main window nad before opening child window I pass some params:
ConfigurationWindowController * wc=[[ConfigurationWindowController alloc] initWithWindowNibName:@"Configuration"];
mConfigWindow = wc;
[mConfigWindow setValuesToURL:@"some string here" storageParam:@"another string" callerWindowPtr:self];
[wc showWindow:self];
This method is successfully called I see values stored in the "child" window class instance properties. However when I try to assign this values to the textfileds in the setValuesToURL method GUI elements are still null , I tried to assign stored strings in awakeFromNib method but here these properties are null! . Also value of self pointer is different - that means object created initWithWindowNibName and actual window with GUI are different. Obviously stored pointer to the "Main" window also is null when I try to pass back values. I suspect that problem is in NIB setup - really confusing to me. I suspect is common misunderstanding of code/NIB relations, I tried different things but still cant get it work. Any guidance would be really useful.
-(void) setValuesToURL:(NSString*)strServiceURL storageParam:(NSString*) strStorageURL callerWindowPtr:(AppletAppDelegate *)_callerWindow
{
@try {
NSLog(@"setValuesToURL was called with params %@ , %@" , strServiceURL , strStorageURL);
self.strDataStorageURL = strStorageURL;
self.strServerURL = strServiceURL;
self.callerWindow = _callerWindow;
[textServerURL setStringValue:[self strServerURL]];
[textDataStorageURL setStringValue:[self strDataStorageURL] ];
NSLog(@" after assigmnemnt %@ , %@" , [self strDataStorageURL], [self strServerURL]);
}
@catch (NSException * e) {
NSLog(@"exception inf0 %@ " ,[[ e userInfo] descriptionInStringsFileFormat]);
}
@finally {
}
}
Good news - now string values are assigned to the NSTextField objects. I have a button on "child" window and on click I'm trying to call back parent pointer window methid :
- (IBAction) saveConfigurationSetings: (id) sender
{
NSLog(@"saveConfigurationSetings: (id) sender");
//close window and pass back URL strings
self.strServerURL = [textServerURL stringValue];
self.strDataStorageURL = [textDataStorageURL stringValue];
[self.callerWindow passMeBackData: [textServerURL stringValue] strStorageURLParam: [textDataStorageURL stringValue]];
[self close];
}
Here callerWindow variable is null and passMeBackData fails . Here is declaration in h :
@interface ConfigurationWindowController : NSWindowController {
...
AppletAppDelegate *callerWindow;
...
}
@property (assign) AppletAppDelegate * callerWindow;
in m file
@synthesize callerWindow;