objective-c - 多窗口 Mac 应用程序

标签 objective-c macos cocoa nswindowcontroller nsviewcontroller

我想制作一个多窗口 Mac 应用程序,但我被多窗口部分困住了!

我可以通过创建 xib 文件并使用此方法来显示一些窗口:

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

@property(强,非原子)AddProdutWindowController *windowController;

在我的头文件中,AddProductViewController继承自NSWindowViewController

我已将 Xcode 中的 NSViewController 子类链接到我的 xib 文件。

现在我想将一些数据发送到我的新 View 并在一些 NSTextField 中显示它们,但我不知道如何做到这一点!

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

感谢您的帮助。

最佳答案

试试这个:

你的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/

相关文章:

objective-c - NSTask NSPipe - objective c 命令行帮助

objective-c - 如何在 Kiwi 中 stub 方法 block ?

objective-c - 为应用程序创建 URI

c - 在 Mac 上安装 flex(词法分析器)

iphone - OCUnit 和 OCMock 在 iPhone SDK 上工作吗?

objective-c - NSJSONSerialization 中不可变的 NSJSONReadingOptions

objective-c - 为什么 UIBarButtonItem 在设置为 UITextField 的 inputAccessoryView 的 UIToolbar 中没有获得点击?

Mac 上的 C++ 套接字服务器。帮助!

objective-c - 如何以编程方式将字体复制到/System/Library/Fonts/?

swift - 如何在 Swift Cocoa 中检测 OS X 中的用户不活动?