0

我想制作一个多窗口mac应用程序,我坚持使用多窗口部分!多窗口mac应用程序

我可以通过创建一个XIB文件,并使用该方法来显示一些窗口:

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

随着 @property (strong, nonatomic) AddProdutWindowController *windowController;

在我的头文件

,并从NSWindowViewController

我已经联系AddProductViewController承继将Xcode中的NSViewController的子类别转换为我的xib文件。

现在我想发送一些数据到我的新视图,并在一些NSTextField显示他们,我没有一个线索如何做到这一点!

我很困惑与WindowsControllerViewController,我不完全知道如何/在哪里使用它们。

谢谢你的帮助。

回答

0

试试这个:

您firstWindowController.h:

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

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

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

您secondWindowController.h:

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

@end 

您secondWindowContr oller.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 
}