I’m new with Cocoa and XCode, I would like to receive your help. I made my Controller of the XIB Window, and started my window and I have one parameter that I want to my controller need to have, y set the parameter but when I click a Button and I need to recover the parameter the value is nill or empty.
For example…
I have
#import <Cocoa/Cocoa.h>
#import "ITKExample1Filter.h"
#import "Helper.h"
@interface VentanaGraficaController1 : NSWindowController {
ViewerController* _viewerController;
IBOutlet NSComboBox *combo;
IBOutlet NSTextField *windowLevelTextField;
IBOutlet NSTextField *windowWidhTextField;
NSString *cad_;
}
@property NSString *cad;
@property ViewerController* viewerController;
//Metodos
- (IBAction) converToRGB: (id)sender;
- (IBAction) initAux: (id)sender;
- (void) initController : (ViewerController*) vc: (int) n;
@end
@implementation VentanaGraficaController1
//Parametros que sintetizaremos para manejar los valores por referencia
@synthesize viewerController = _viewerController;
@synthesize cad = cad_;
// .....
- (IBAction) converToRGB: (id)sender {
NSAlert *a = [NSAlert alertWithMessageText:cad_
defaultButton:@"OK"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"Cadena por syntetise"];
[a runModal];
}
// ..... The rest
I use my controller as follow:
VentanaGraficaController1 *controller = [[VentanaGraficaController1 alloc] initWithWindowNibName:@"VentanaGraficaController1"];
[controller setViewerController:viewerController];
[controller setViewerController:(viewerController)];
[controller setCad:@"works??"];
controller.viewerController = viewerController;
controller.cad = @"works??";
[controller showWindow:nil];
When I display the NSSAlert it always show me cad_ as a blank or empty string, I have tried a lot of ways, but I dont know why I lose the value.
Looks like you’re not telling your controller to retain your properties.
You have
Which defaults to assigning values, which means they could disappear on you.
Try changing those lines to: