2

I want to make a multiple windows mac application and I am stuck with the multiple window part !

I can display some windows by creating a xib file and using this method :

-(void)popView:(NSString *)viewName {
    _windowController = [[AddProdutWindowController alloc] initWithWindowNibName:viewName];
    [_windowController showWindow:nil];
}

With @property (strong, nonatomic) AddProdutWindowController *windowController;

in my header file and AddProductViewController inherit from NSWindowViewController

I have linked a subclass of NSViewController in Xcode to my xib file.

Now I want to send some datas to my new view and show them in some NSTextField and I have not a single clue how to do it !

I'm very confused with the WindowsController and ViewController, I don't exactly know how / where use them.

Thank you for helping.

Edelweiss
  • 621
  • 1
  • 9
  • 24

1 Answers1

0

Try this:

your firstWindowController.h:

#import <Cocoa/Cocoa.h>
@class SecondWindowController;

@interface ResultWindowController : NSWindowController{
   SecondWindowController *swc;
}
@property  (assign) NSNumber *xyz;
...

your firstWindowController.m:

#import "FirstWindowController.h"
#import "SecondWindowController.h"

@implementation FirstWindowController
@synthesize xyz;


- (IBAction)openSecondWindow:(id *)sender {
if (!swc)
{
    swc = [[SecondWindowController alloc] init];
}
[Swc setFwc:self];
[Swc showWindow:self];

your secondWindowController.h:

#import <Cocoa/Cocoa.h>
@class FirstWindowController;
@interface SecondWindowController : NSWindowController {
   FirstWindowController *fwc;
}
@property (retain) IBOutlet FirstWindowController *fwc;

@end

your secondWindowController.m:

#import "SecondWindowController.h"
#import "FirstWindowController.h"

@implementation SecondWindowController
@synthesize fwc;


- (id)init
{
if(![super initWithWindowNibName:@"SecondWindow"])
    return nil;
NSLog(@"_init: %@", NSStringFromClass([self class]));

return self;
}

- (void)windowDidLoad
{
[super windowDidLoad];

NSLog(@"swc didload self=%p", self); //thats your second window controller

NSLog(@"fwc value is %@", fwd.xyz);  // here you should be able to see the value from FirtsWindowController
}
JFS
  • 2,992
  • 3
  • 37
  • 48