我想制作一个多窗口 Mac 应用程序,但我被多窗口部分困住了!
我可以通过创建 xib 文件并使用此方法来显示一些窗口:
-(void)popView:(NSString *)viewName {
_windowController = [[AddProdutWindowController alloc] initWithWindowNibName:viewName];
[_windowController showWindow:nil];
}
与
@property(强,非原子)AddProdutWindowController *windowController;
在我的头文件中,AddProductViewController
继承自NSWindowViewController
我已将 Xcode 中的 NSViewController
子类链接到我的 xib
文件。
现在我想将一些数据发送到我的新 View 并在一些 NSTextField
中显示它们,但我不知道如何做到这一点!
我对 WindowsController
和 ViewController
非常困惑,我不完全知道如何/在哪里使用它们。
感谢您的帮助。
最佳答案
试试这个:
你的firstWindowController.h:
#import <Cocoa/Cocoa.h>
@class SecondWindowController;
@interface ResultWindowController : NSWindowController{
SecondWindowController *swc;
}
@property (assign) NSNumber *xyz;
...
你的第一个WindowController.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];
你的第二个WindowController.h:
#import <Cocoa/Cocoa.h>
@class FirstWindowController;
@interface SecondWindowController : NSWindowController {
FirstWindowController *fwc;
}
@property (retain) IBOutlet FirstWindowController *fwc;
@end
你的第二个WindowController.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
}
关于objective-c - 多窗口 Mac 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962044/